0.0
No commit activity in last 3 years
No release in over 3 years
respond_with gon
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

~> 5.0
 Project Readme

GonResponder

GonResponder module for responders gem

Installation

Add this line to your application's Gemfile:

gem 'gon_responder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gon_responder

Usage

Add GonResponder module to your ApplicationResponder like this:

class ApplicationResponder < ActionController::Responder

  include Responders::FlashResponder
  include Responders::HttpCacheResponder
  include Responders::GonResponder
end

Now you're ready to respond_with gon:

class PostsController < ApplicationController
  respond_to :html, :json

  def index
    @posts = Post.all
    respond_with @posts, gon: { rabl: { as: :posts }}
  end

You should add gon options hash to respond_with.

Example

respond_with @posts, gon: { :posts= => @posts }

Which equals to

gon.posts = @posts

Another example

respond_with @posts, gon: { push: { user_id: 1, user_role: "admin" } }

Which equals to

gon.push({ :user_id => 1, :user_role => "admin" })

RablRails example

respond_with @posts, gon: :rabl

Which equals to

gon.rabl

Another RablRails example

respond_with @posts, gon: { rabl: { template: 'app/views/posts/index.json.rabl', as: :posts } }

Which equals to

gon.rabl template: 'app/views/posts/index.json.rabl', as: :posts

Contributing

  1. Fork it ( https://github.com/kressh/gon_responder/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request