0

I am trying to pass the index of something into a partial and am getting a NameError.

Right now, this is my render statement and I am able to access builder just fine.

<%= render 'my_partial', :builder => form_helper %>

But when adding index like below, I get the error.

<%= render 'my_partial', :builder => form_helper, :locals => {:index => index } %>

Any thoughts? Thanks!

edit:

While trying

<%= render :partial => 'my_partial', :locals => {:builder => form_helper, :index => index } %>

The specific error is "undefined local variable or method `index' for #<#:0x007fc37206ae40>"

JuliaC
  • 121
  • 1
  • 2
  • 11

1 Answers1

2

Either:

 <%= render 'my_partial', :builder => form_helper, :index => index %>

Or:

<%= render :partial => 'my_partial', :locals => {:index => index, :builder => form_helper } %>
apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • And then I should be able to access index by just writing '<%= index %>' in my partial? – JuliaC Apr 05 '13 at 14:31
  • From the [Ruby on Rails Guides](http://guides.rubyonrails.org/layouts_and_rendering.html#partial-layouts): "Also note that explicitly specifying `:partial` is required when passing additional options such as `:layout`." Same applies when passing `:locals` – Stefan Apr 05 '13 at 14:32
  • I am trying the second option in apneadiving's post above and while builder still works correctly, it still says undefined local variable or method 'index'. Does it matter that index is just an integer? – JuliaC Apr 05 '13 at 14:37
  • @apneadiving I know, I just wanted to add a reference to the documentation. – Stefan Apr 05 '13 at 14:38
  • Added the wording back in my original description! – JuliaC Apr 05 '13 at 14:44
  • **ALSO: Would it make a difference that it's technically passing from one partial to another? – JuliaC Apr 05 '13 at 15:03