Reputation: 2273
I have a _form
partial for surv_rdsap_xrefs
controller.
I want to keep the error
methods in the form
and the fields
are rendering from two different folders. one is condtion/rdsap_xrefs/_surv_rdsap_xrefs
and another is section/condition/_question
.
<%= form_for(@enr_rds_surv_rdsap_xref) do |f| %>
<% if @enr_rds_surv_rdsap_xref.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@enr_rds_surv_rdsap_xref.errors.count, "error") %>:</h2>
<ul>
<% @enr_rds_surv_rdsap_xref.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="left">
<%= render 'section/condition/_question' %>
</div>
<div class="right">
<%= render 'condition/rdsap_xref/surv_rdsap_xref' %>
</div>
<% end %>
Now, i got the error of undefined method of f
in the partials. How to partial these two for the same form. Thanks
Upvotes: 1
Views: 292
Reputation: 6026
for your error you must pass locals f in your partial so that
write this, for section/condition/_question
<%= render 'section/condition/_question', f: f %>
and for condition/rdsap_xref/surv_rdsap_xref this
<%= render 'condition/rdsap_xref/surv_rdsap_xref', f: f %>
Upvotes: 2
Reputation: 5213
try this
<div class="left">
<%= render 'section/condition/_question', f: f %>
</div>
<div class="right">
<%= render 'condition/rdsap_xref/surv_rdsap_xref', f: f %>
</div>
<% end %>
As in partials there must be a variable f
to which you have to assign some value. Thats why I have assigned the f
of form_for
into the partial variable f
Upvotes: 2