I've spent considerable amount of time making a form in simple_form. It had 96 fields! I've split the form in different steps. Each step is made as a partial.
Now I have to prepare the form for show.html.erb
. I thought rendering the same partials would just show the form to the user but ofcourse If I try to do that it gives me an error like:
undefined local variable or method `f' for #<#<Class:0xb6d8712c>:0xb6d85f20>
Most of my partials have code like below:
<%= f.input :name, :label=>"Preferred Name",:label_html => {:class => "form_label"}%>
I am just trying to leverage the work I've done instead of coding all fields again for show.html.erb
Are there any tricks I can use here?
You should be sending show.html.erb
's form_for
builder variable when rendering the partial:
#show.html.erb
<%= simple_form_for @something do |builder| %>
<%= render :partial => 'somepartial', :locals => { :f => builder } %>
...
<% end %>
#_somepartial.html.erb
<%= f.input :name, :label=>"Preferred Name",:label_html => {:class => "form_label"} %>