Rails passing form_for object to partial

Harry picture Harry · Sep 3, 2012 · Viewed 17.5k times · Source

I would like to pass the form_for object to a partial:

<%= form_for @price do |f| %>
   ...
   <%= render :partial => "price_page", :object => @price, :as => :f %>
   ...
<% end %>

When I call:

f.radio_button

Brings the error:

undefined method `radio_button' for #<Price:0x3cb1ed0>

How can I use f as I usually would in this partial?

Answer

Amar picture Amar · Sep 3, 2012

Try passing form object as local <%= render :partial => "price_page", :locals=>{:f=>f} %>