I have some Javascript to which I need to assign a ruby string. In this case I have some javascript functions written that require logged in users' email address. I am using haml.
In my application layout file (application.html.haml) I could do this and it will work:
%script{:type => "text/javascript", :charset => "utf-8"}
$(document).ready(function () {
alert('hello'+ "#{User.find(current_user).email}");
});
but I have a dedicated js file for my app. application.js file
How Can I pass the logged in user's email address to application.js file from my view??
The following in application.js does not work.
$(document).ready(function () {
alert('hello' + "#{User.find(current_user).email}");
});
User.find(current_user)out of the view and into the controller by setting the result of that query to@current_user- keeps the code base more MVC and in the long run, more readable and manageable.