Rails form_for collection_select ignores the remote ajax call that select_tag accepts

Before using my form helper, I used below for the drop-down list:

<%= select_tag :city_id, options_for_select( City.all.collect{|c| [c.name,c.id]} ), :data => { :remote => true, :url => url_for(:controller => "locations", :action => "filter_by_city") } %> 

and it worked fine for calling my filter_by_city.js.erb and updating some other values. Checking with firebug shows that it has data, deleted, etc., Properties.

However, instead of going to form_for helper below, I do not receive any deleted data and therefore do not call AJAX.

 <%= f.collection_select(:city_id, City.all, :id, :name, :data => { :remote => true, :url => url_for(:controller => "locations", :action => "filter_by_city") } ) %> 

The dropdown menu looks exactly the same as before (and it took some confusion with the parameters to get this parameter), but it has no functions other than setting the params value.

I tried wrapping: data in {} (as from the French forum here , but that was not a cure.

I suppose this is a beginners mistake, but any help finding it would be appreciated.

thanks

+4
source share
1 answer

:: le sigh ::

When using the collection_select function, unlike some parts of RoR, it seems a bit meticulous to include all arguments in order. Despite the fact that I can (and continue) to leave: post, the solution turned out to include an empty set for parameters and wrapping: data in {} for html_options.

So here is what works:

 <%= f.collection_select(:city_id, City.all, :id, :name, {}, {:data => { :remote => true, :url => url_for(:controller => "locations", :action => "filter_by_city") } } ) %> 

Note the {} after: name and {the beginning of the next line.

Check-out - OPTIONS NOT OPTIONAL if html_options is enabled.

+7
source

Source: https://habr.com/ru/post/1401119/