|
7 | 7 |
|
8 | 8 | If you need to send some data to your js files and you don't want to do this with long way through views and parsing - use this force! |
9 | 9 |
|
10 | | -Now with [Jbuilder](https://github.com/rails/jbuilder) and [Rabl](https://github.com/nesquena/rabl) support! |
| 10 | +With [Jbuilder](https://github.com/rails/jbuilder) and [Rabl](https://github.com/nesquena/rabl) support! |
11 | 11 |
|
12 | 12 | For Sinatra available [gon-sinatra](https://github.com/gazay/gon-sinatra). |
13 | 13 |
|
@@ -129,7 +129,7 @@ alert(customNamespace.yourHash) |
129 | 129 |
|
130 | 130 | ## Usage with Rabl |
131 | 131 |
|
132 | | -Now you can write your variables assign logic to templates with [Rabl](https://github.com/nesquena/rabl). |
| 132 | +You can write your variables assign logic to templates with [Rabl](https://github.com/nesquena/rabl). |
133 | 133 | The way of writing Rabl templates is very clearly described in their repo. |
134 | 134 |
|
135 | 135 | Add Rabl to your Gemfile before requiring gon - because gon checks Rabl constant |
@@ -297,18 +297,42 @@ alert(gon.comments[0]) |
297 | 297 | P.s. If you didn't put include_gon tag in your html head area - it |
298 | 298 | wouldn't work. You can read about this in common usage above. |
299 | 299 |
|
| 300 | +## gon.global |
| 301 | + |
| 302 | +Now you can use gon for sending your data to js from anywhere! |
| 303 | + |
| 304 | +It works just as simple `gon` but you need to write `Gon.global` instead of `gon` in your ruby code, |
| 305 | +`gon.global` in javascript and it will not clear self after each request. All other things the same. |
| 306 | + |
| 307 | +For example I want to tell anybody my application session secret token :) Now with Gon.global it's easy! |
| 308 | + |
| 309 | +`config/initializers/secret_token.rb` |
| 310 | + |
| 311 | +```ruby |
| 312 | +GonTest::Application.config.secret_token = 'You can't see my token' |
| 313 | +Gon.global.session = 'You can't see it I said' |
| 314 | +``` |
| 315 | + |
| 316 | +`in some js which can reach window.gon variable` |
| 317 | + |
| 318 | +```javascript |
| 319 | +alert(gon.global.session) |
| 320 | +``` |
| 321 | + |
| 322 | +Thats it! |
| 323 | + |
300 | 324 | ## Installation |
301 | 325 |
|
302 | 326 | Puts this line into `Gemfile` then run `$ bundle`: |
303 | 327 |
|
304 | 328 | ``` ruby |
305 | | -gem 'gon', '2.3.0' |
| 329 | +gem 'gon', '3.0.0' |
306 | 330 | ``` |
307 | 331 |
|
308 | 332 | Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`: |
309 | 333 |
|
310 | 334 | ``` ruby |
311 | | -config.gem 'gon', :version => '2.3.0' |
| 335 | +config.gem 'gon', :version => '3.0.0' |
312 | 336 | ``` |
313 | 337 |
|
314 | 338 | Or manually install gon gem: `$ gem install gon` |
|
0 commit comments