# Model select and non-model select\_tag

**URL:** <https://www.ruby-forum.com/t/model-select-and-non-model-select-tag/133957>\
**Category:** Rails\
**Created:** [April 5, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/model-select-and-non-model-select-tag/133957 "2008-04-05T15:55:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [April 5, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/model-select-and-non-model-select-tag/133957/1 "2008-04-05T15:55:40Z")

</div>

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 “%{Please Select…}” kludge I have  
above.

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

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [April 5, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/model-select-and-non-model-select-tag/133957/2 "2008-04-05T16:14:28Z")

</div>

On Apr 5, 2:55 pm, John L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I want to do the same for a non-model field, logic would dictate
> 
> 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

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [April 6, 2008, 11:39pm UTC](https://www.ruby-forum.com/t/model-select-and-non-model-select-tag/133957/3 "2008-04-06T23:39:48Z")

</div>

Having looked into non-model fields there are also inconsistencies  
between the various non-model fields. For instance, we have select\_tag  
and text\_field\_tag but for dates it is date\_select rather than  
date\_select\_tag as one would expect.

It seems to me that it would make lots more sense if there was a  
consistent model and non-model set of field helpers that took similar  
arguments.

ie, model field:  
\<%= form.select :card\_type, supported\_card\_types,  
{ :prompt =\> “Please Select…”} %\>

and non-model field:  
\<%= select :card\_type, supported\_card\_types,  
{ :prompt =\> “Please Select…”} %\>

Something perhaps that could be considered for a future version of Rails  
?
