How to render a form partial in Rails 4?

ruby-on-rails, ruby-on-rails-4

Solution

You only use `:locals` when you use `:partial`.

Either of these are correct:

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

Or (as of Rails 2.3):

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

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

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

Problem

undefined local variable or method `f' for #<#:0x000001080edfe0> I am trying to render a form within a template page with: ``` <%= form_for @vehicle, html: { class: "f_grp" }, remote: true do |f| %> <%= render "vehicles", locals: { f: f } %> <% end %> ``` The file is loading. But I'm getting an undefined method on `f` error. Any ideas?

Original source