Reputation: 21536
I've seen the other posts, but can't seem to figure out why this isn't working for me
In my controller I set
@referrer=referrer.name
in my view i have
<%= render 'js', :referrer => @referrer >
then in my partial i put
var type =' <%= referrer >';
I get a response 'undefined local variable or method 'referrer' and it points to the _js file.
from what I can see, this is exactly how it is supposed to be written, what am I doing wrong?
Upvotes: 0
Views: 440
Reputation: 84150
<%= render :partial => "account", :locals => { :referrer => @referrer } %>
Your variables to use in the partial need to be passed via the :locals hash.
Reference: http://api.rubyonrails.org/classes/ActionView/Partials.html
EDIT
The following works perfectly for me:
Controller:
def index
@referrer = "test"
end
index.html.erb
<%= render :partial => "account", :locals => { :referrer => @referrer } %>
_account.html.erb
<%=referrer%>
Upvotes: 2
Reputation: 21536
Turns out the reason was that in the partial, I had to call
var type='<%= @referrer %>'
not sure why all the other documentation i'd seen had it without the @ symbol
Upvotes: 0