6

I am rendering a partial like so:

 <% @pages.each do |page| %>
     <%= render 'layouts/pagewithchildren', :locals => { :page => page } %>
 <% end %>

But when i try to access a variable in page i am getting the error:

undefined local variable or method `page'

I am accessing the variable like:

<%= page.title %>

So what else do I need to do?

4

2 に答える 2

8

私は100%確信はありませんが、そうではありません

<%= render 'layouts/pagewithchildren', :page => page %>

また

<%= render :partial => 'layouts/pagewithchildren', :locals => { :page => page } %>

于 2012-08-31T13:47:42.117 に答える
8

You have to explicitly specify partial, otherwise, Rails will treat locals as a params hash, you can access locals[:page] but not page variable directly in your partial.

Change your code to:

<%= render partial:'layouts/pagewithchildren', locals: {page: page} %>
于 2014-02-17T19:25:31.587 に答える