Skip to content
gazay edited this page Jun 22, 2012 · 4 revisions

Now you can use gon for sending your data to js from anywhere!

It works just as simple gon but you need to write Gon.global instead of gon in your ruby code, gon.global in javascript and it will not clear self after each request. All other things remain the same.

For example I want to set start data into gon, which will be there before I clear it.

Maybe some configuration data or url address which should be present on each page with include_gon helper in head.

Now with Gon.global it's easy!

config/initializers/some_initializer.rb or any file where you can reach Gon constant

Gon.global.variable = 'Some data'

in some js which can reach window.gon variable

alert(gon.global.variable)

Thats it!

Clone this wiki locally