You can customize your user information in a global JavaScript variable:
%script{:type => "text/javascript", :charset => "utf-8"} var user = { email: "#{escape_javascript User.find(current_user).email}" } $(document).ready(function () { alert('hello ' + user.email); });
and then turn off in application.js
:
$(document).ready(function() { alert('hello ' + user.email); });
And your page should say hello twice.
Also, usually current_user
will not be a user instance? If so, then current_user.email
should be enough, and if not, then set that you want to set @user = ...
in your controller, and then use @user.email
in your view.
I hope I understood HAML correctly, I don’t use it, so I’m kind of guessing the syntax.
source share