After I call the ajax method, the escape_javascript function spits out </div> </div> </div>
for each item being rendered. I've checked all my closing tags, two and three times over, and I can't find an error. Is the formbuilder instantiated properly?
controller method
def add_new_plan
new_plan = Plan.find(params[:plan_id])
@customer = Customer.find(params[:customer_id)
CustomerPlan.create(...)
# Pass a form builder to the nested form
@f = ActionView::Helpers::FormBuilder.new(:customer, @customer, view_context, {})
respond_to do |format|
format.js
end
end
js.erb
$("#customerPlan").html(
'<%= j( render("plan_tab1", f: @f) ) %>'
);
A mock sample of the html
<div>
<div>
form collection loop
all form elements should be contained here
</div>
but the FormBuilder is outputting hidden fields here
</div>
the hidden fields are rendered altogether, not in their respective form iterations. (Note that the quotation marks in the inspector are not visible on the rendered page.)
I was updating a form within another form. Converted to the use of two separate forms, linking with a single update button via JS. The problem was that the first form <% end %>
tag was still open after the ajax call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.