This might be a very simple question, but I could not find the answer for it. How should I access a rails session variable from javascript/jQuery (from a Backbone view)? Most likely this is not the best practice, but this is not a problem for me.
Thank you,
Alexandra
You can use the gon gem. It allows to send data automatically with each request and let it be accessible from javascript.
For example, after including the gem in your Gemfile, you can add a before filter to your ApplicationController:
In your application layout, section head of your html:
Now you can read this value from your javascript:
This way you only include data specific to the request in your ajax response, and all your extra info is available from the gon variable.