(Beware that only publicly available information should be available on the client side)
For a more elegant solution, you can create a UserSession
Backbone and fetch
model from the server as a regular Backbone model.
window.App.UserSession = Backbone.Model.extend({ urlRoot: "/session" });
If you do not want to make this additional request, you can explicitly load the model with the data already available in the process of rendering the template:
window.App.current_user = new window.App.UserSession({ id: "#{current_user.id}", token: "#{current_user.token}" });
source share