colbern
colbern

Reputation: 11

Rails 3: "undefined local variable or method" if I put content in a partial

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

Upvotes: 0

Views: 2352

Answers (1)

KARASZI Istv&#225;n
KARASZI Istv&#225;n

Reputation: 31477

You need to add the msg variable to the locals of the partial template.

<%= render :partial => "rating", :locals => { :msg => msg } %>

Upvotes: 2

Related Questions