问题
I have the following table
<table id="rating">
<thead>
<tr>
<th colspan="2">Photo Ratings</th>
</tr>
<tr>
<td>Average Rating</td>
<td><%= msg.average_rating %></td>
</tr>
<tr>
<td>Your Rating</td>
<td><%= current_user_rating %></td>
</tr>
</thead>
</table>
Which works fine if I have it in a view, but when I put it in a partial _rating.html.erb
I get
undefined local variable or method 'msg' for #<#<Class:0x000003463da1570>:0x003463d9f388>
I am linking to the partial via <%= render :partial => "rating" %>
, what must I add to the partial link so that I dont get the error? Thanks
回答1:
You need to add the msg
variable to the locals of the partial template.
<%= render :partial => "rating", :locals => { :msg => msg } %>
来源:https://stackoverflow.com/questions/7128123/rails-3-undefined-local-variable-or-method-if-i-put-content-in-a-partial