Skip to content

Commit ed05c3c

Browse files
committed
Thanks to @moktin! Bump version with default view paths
1 parent 12a904a commit ed05c3c

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,31 +149,45 @@ Profit of using Rabl with gon:
149149
5. And so on
150150
151151
For using gon with Rabl you need to create new Rabl template and map gon
152-
to it.
152+
to it.
153153
For example you have model Post with attributes :title and :body.
154154
You want to get all your posts in your js as an Array.
155155
That's what you need to do:
156156

157-
1. Create Rabl template. I prefer creating special directory for
158-
templates which are not view templates.
157+
1. Create Rabl template. You can choose spepicific directory but better
158+
use default directory for action.
159159

160-
`app/goners/posts/index.rabl`
160+
`app/views/posts/index.json.rabl`
161161

162162
``` rabl
163163
collection @posts => 'posts'
164164
attributes :id, :title, :body
165165
```
166166

167-
2. All you need to do after that is only to map this template to gon.
167+
2. If you create template in default directory for action, you just write in this action:
168168

169-
`app/controllers/post_controller.rb#index`
169+
`app/controllers/posts_controller.rb#index`
170170

171171
``` ruby
172172
def index
173173
# some controller logic
174174
@posts = Post.all # Rabl works with instance variables of controller
175175
176-
gon.rabl 'app/goners/posts/index.rabl'
176+
gon.rabl
177+
# some controller logic
178+
end
179+
```
180+
181+
But if you choose some specific category - you need to map this template to gon.
182+
183+
`app/controllers/posts_controller.rb#index`
184+
185+
``` ruby
186+
def index
187+
# some controller logic
188+
@posts = Post.all # Rabl works with instance variables of controller
189+
190+
gon.rabl :template => 'app/goners/posts/index.rabl'
177191
# some controller logic
178192
end
179193
```
@@ -217,7 +231,7 @@ gon mapping method:
217231
``` ruby
218232
# your controller stuff here
219233
220-
gon.rabl 'path/to/rabl/file', :as => 'alias'
234+
gon.rabl :as => 'alias'
221235
```
222236
223237
## Usage with Jbuilder
@@ -243,7 +257,8 @@ Jbuilder works now only on Ruby 1.9+, so Gon support for Jbuilder works on 1.9+
243257
json.posts @posts, :id, :title, :body
244258
```
245259
246-
2. In your controller you should map this template to gon.
260+
2. In your controller you should just call 'gon.jbuilder' - if your template in
261+
default directory for action. In the other case - you still can use :template option.
247262
248263
``` ruby
249264
def index
@@ -287,13 +302,13 @@ wouldn't work. You can read about this in common usage above.
287302
Puts this line into `Gemfile` then run `$ bundle`:
288303

289304
``` ruby
290-
gem 'gon', '2.1.2'
305+
gem 'gon', '2.2.0'
291306
```
292307

293308
Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
294309

295310
``` ruby
296-
config.gem 'gon', :version => '2.1.2'
311+
config.gem 'gon', :version => '2.2.0'
297312
```
298313

299314
Or manually install gon gem: `$ gem install gon`

lib/gon.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
if RUBY_VERSION > '1.9' && defined?(Jbuilder)
32
gem 'blankslate'
43
end

lib/gon/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Gon
2-
VERSION = '2.1.2'
2+
VERSION = '2.2.0'
33
end

0 commit comments

Comments
 (0)