Jump to content

The ultimate community for Ruby on Rails developers.


Retrieve form builder object on ajax callback

form builder ajax partials

  • Please log in to reply
1 reply to this topic

#1 uriklar



  • Members
  • 4 posts

Posted 11 November 2013 - 08:24 AM

Hi all,

I have implemented an action that gets called by Ajax and renders a js.erb file. The rendered js should render a partial that has fields_for a nested model. My problem is, I need to pass the partial the original form_builder object. But how can I retrieve this object after returning from an Ajax call? Do you have any ideas? 

Some code to help you understand my issue.


this is a partial rendered from the main form page:



= render 'some_partial', {object: @object , f: f }
On my ajax callback I replace the render tag with a new one with the update object.
.html("<%= j render(:partial => 'some_partial', :locals => {object: @object,:f => f }) %>");

How can I get this f parameter to pass on the the partial??
Thanks to all helpers!




#2 uriklar



  • Members
  • 4 posts

Posted 11 November 2013 - 09:18 AM

A solution currently working for me is creating a new form in the js.erb file and passing that one to the partial. Because it's created from the same object rails somehow allows it..

'<%= simple_form_for(@object) do |ff|  %>'
.html("<%= j render(partial: 'xome_partial', locals: {object: @object, f: ff }) %>");
'<% end %>'
The single quotes around the form tag are important, or else there is a javascript escaping problem.

Also tagged with one or more of these keywords: form, builder, ajax, partials

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users