model select and non-model select_tag

Hello everyone, I'm just trying to understand some logical reasons behind Rails syntax of "select" and "select_tag".

I know I can do this:

        <%= form.select :card_type, supported_card_types,                        { :prompt => "Please Select..."} %>

which sets a model field in the params hash.

If I want to do the same for a non-model field, logic would dictate something like:

        <%= select :card_type, supported_card_types,                        { :prompt => "Please Select..."} %>

However what is required is like this:

        <%= select_tag :card_type,                        %{<option value="">Please Select...</option>} +                        options_for_select(supported_card_types) %>

It seems very odd to me that select_tag can not follow the same (and elegent) syntax of select so model and non-model fields can be coded the same way.

It seems particularly odd that the latter requires use of "options_for_select" and does not support :html_options. The lack of the :html_options means you can not use :prompt so have to resort to the nasty "%{<option value="">Please Select...</option>}" kludge I have above.

I expect there is a good reason for this that I can not see...

Hello everyone, I'm just trying to understand some logical reasons behind Rails syntax of "select" and "select_tag".

I know I can do this:

    &lt;%= form\.select :card\_type, supported\_card\_types,
                   \{ :prompt =&gt; &quot;Please Select\.\.\.&quot;\} %&gt;

which sets a model field in the params hash.

If I want to do the same for a non-model field, logic would dictate something like:

    &lt;%= select :card\_type, supported\_card\_types,
                   \{ :prompt =&gt; &quot;Please Select\.\.\.&quot;\} %&gt;

However what is required is like this:

    &lt;%= select\_tag :card\_type,
                   %\{&lt;option value=&quot;&quot;&gt;Please Select\.\.\.&lt;/option&gt;\} \+
                   options\_for\_select\(supported\_card\_types\) %&gt;

It seems very odd to me that select_tag can not follow the same (and elegent) syntax of select so model and non-model fields can be coded the same way.

There's a bit of history here. Before rails 1.2 there was no form_for, and so helpers split into two families: select, text_field, check_box etc... who all took as there first argument the name of an instance variable and as their second the name of a method (note that this never had to correspond to an actual database attribute) and select_tag, text_field_tag etc... who just generated the appropriate tag given the name and the value for when what you were doing didn't fit that pattern. They aren't as smart because they make fewer assumptions about what you are trying to do. form_for allowed you to stop repeating that first parameter for each field in the form and also allow escaping the convention of the instance variable.

Fred