Skip forward form in remote_function in rails?

I have a selection field where, when changing, I need to capture the value, and through a remote function, get some field names from db, and then generate this field further in a form showing what is selected from the selection window.

The problem is that the fields are in f.form_for, so they use formbuilder f, which has a select box. Therefore, when I process partial through ajax in the controller, I get an error because I do not have a link to the local form builder.

Does anyone know how or if I can get a link to the form builder, orif can pass it in a remote function call, and then pass my locales in partial?

Thanks a lot, any help would be great as it stuck on this for a long time!

amuses Rick

+5
source share
4 answers

I had the same problem and my solution was to create another form constructor for the same object and pass it partial.

remote_action.js.erb:

'<%= form_for(@object) do |ff| %>'
   $('#some_div').html("<%= j render(partial: 'some_partial', locals: {f: ff}) %>"
'<% end %>' 

It is important that the form_for tag has single quotes, otherwise there will be problems with javascript_escape.

+18
source

I would just rewrite your partial so as not to use f. helper forms.

make:

<%= text_field :object_name, :method_name %>

Instead:

<%= f.text_field :method_name %>
+7
source

- , , , :

# create a form helper 'f' and store it in the variable form_helper.

<% form_helper = nil %> 
<% form_for @object, url: '' do |f| %>
<%   form_helper = f %>
<% end %>

# pass form_helper to the form partial

$('#element').html('<%= j render "form_element", f: form_helper %>');

, form_helper = nil , , .

, , - , .

+3

... , /. , @object :

'<%= form_for([@property.agency,@property]) do |parent_form| %> ' '<%= parent_form.fields_for :address do |f| %>' $('#property_addresses').append("<%= j render(partial: 'common_partials/address', locals: {parent_form: f}) %>") '<% end %>' '<% end %>'

, @property, @property.agency: form_for.

0

All Articles