Hello!

In rails 3.1 app I have a controller UsersController with 'show' action.
show.html.erb contains:

<% content_for(:head) do %>
<%= javascript_include_tag 'myscript' %>
<% end %>
<p>Hello @user.name</p>

And I have this in myscript.js.erb

$jQuery(document).ready(function() {
alert(<%= @user.name %>);
});

@user is being assigned by a controller and it works just ok in 
show.html.erb, but in myscript.js.erb I get nil as @user and exception is 
thrown.

What's my error here? How to get around this? 
I googled, but all suggestions I found were about rendering partial and 
using :local option to pass a variable to it.
Is this the only option?
I'm asking because I suspect I miss something. It would look really natural 
for @user being accessible in js.erb loaded through 
javascript_include_tag...

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/ocxAmLujxpYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to