Im using rails gon
https://github.com/gazay/gon
to get data from controller easy inserted in views
To get an idea (just an example):
def show
gon.alert = "this is an alert"
end
now inside my show.haml:
:javascript
alert(gon.alert)
Now I always have access to a gon value that i set in controller action before BUT what If you want to access gon values from your application.coffee?
- where to set a gon.current_user = 1 that i can use inside application.coffee?
If you want to set a gon value that you can access from every controller action and thus always available in application.coffee, you can set up a
before_filterin yourApplicationController.That will run the
set_gon_valuesmethod before every action across all of your controllers. This works because all of your controllers inherit fromApplicationController.