dgolman
dgolman

Reputation: 196

Rails 4 rendering partials (undefined local variable or method)

I am trying to pass two local variables to my partial but I am getting this undefined local variable or method `row' for #<#:0x00000105d7f3b0> when using it in the partial.

Render

<%= f.fields_for :menu_items do |builder| %>
<%= render partial: 'menu_item_fields', locals: {f: builder, row: f.options[:child_index]} %>
<% end %>`

Partial

<a href="#" data-target="item-<%= f.options[:child_index].to_s + "-" + row.to_s %>" class="item-field"><%= f.object.title %></a>

Upvotes: 1

Views: 1921

Answers (2)

rails4guides.com
rails4guides.com

Reputation: 1441

I think it should be :

{ f: builder, row: builder.options[:child_index] }

Oops, I misread your code on my mobile phone. Does your code work correctly if you don't call it using a partial?

Upvotes: 0

Ganesh Kunwar
Ganesh Kunwar

Reputation: 2653

Change this code

<a href="#" data-target="item-<%= f.options[:child_index].to_s + "-" + row.to_s %>" class="item-field"><%= f.object.title %></a>

as follows:

<a href="#" data-target="item-<%= f.options[:child_index].to_s + '-' + row.to_s %>" class="item-field"><%= f.object.title %></a>

Upvotes: 1

Related Questions