In this example, we are editing a collection of region records, each with
its own select list of countries. (Region belongs_to :country.) If
the region doesn’t have a country associated, then we want a default
message of “unassigned”. Of course, if the region does have a country
associated then we want that country displayed:

The jquery_ujs looks for data-remote and data-url. These
can be spelled out or placed in the data hash. The url must be formed as select_tag
does not call url_for, unlike some of the other related tags.
Values for application symbols can also be passed through. jQuery triggers
will work on the Ajax events that occur. This generates the following:

For example, tying into the events in this case the program makes visible
an existing hidden progress bar while awaiting a server response, and then
displays a div containing a message returned by the server and
hides the progress bar. If the div contains a class= for
notice or error, then they will fade out.

Sometimes you need to use select_tag
instead of select (because you’re after more control or need to use
optgroups, for example), but still want the id/name conventions that select
would give.

In this case, all you need to do is set the first parameter to whatever
would be produced by select, and it’ll take care of the id and name
attribute automatically, and thus ensure the form data is parsed correctly
after submission.

For example, if you want to do something like:

form_for:commentdo|f|f.select:article_id...

which would give a select tag with id of “comment_article_id” and a
name attribute of “comment[article_id]”, which be parsed into the
params hash of: