How to display part of a form in Rails 4?

undefined local variable or `f 'method for # <#: 0x000001080edfe0>

I am trying to display a form on a template page using

<%= form_for @vehicle, html: { class: "f_grp" }, remote: true do |f| %> <%= render "vehicles", locals: { f: f } %> <% end %> 

The file is loading. But I get the undefined method on error f . Any ideas?

+7
ruby-on-rails ruby-on-rails-4
source share
1 answer

Use :locals only when using :partial .

Is this true:

 <%= render partial: 'vehicles', locals: { f: f } %> 

Or (with Rails 2.3):

 <%= render 'vehicles', f: f %> 

Your version, which combines both, creates the local name locals and sets its value to a hash containing f: FormBuilder...

It's worth noting that the only reason still using locals: is to use render :collection .

+22
source share

All Articles