# Selecting a default value in select helper method

**URL:** <https://www.ruby-forum.com/t/selecting-a-default-value-in-select-helper-method/126531>\
**Category:** Rails\
**Created:** [January 19, 2008, 2:06am UTC](https://www.ruby-forum.com/t/selecting-a-default-value-in-select-helper-method/126531 "2008-01-19T02:06:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [January 19, 2008, 2:06am UTC](https://www.ruby-forum.com/t/selecting-a-default-value-in-select-helper-method/126531/1 "2008-01-19T02:06:12Z")

</div>

How do I select a default value in a blank form when using select vs  
select\_tag?

For example, I have a collection of states and I want the local state  
to be automatically selected when filling out the form.

Am I stuck with using select\_tag and options\_for\_select?

Thanks.

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [January 19, 2008, 9:03am UTC](https://www.ruby-forum.com/t/selecting-a-default-value-in-select-helper-method/126531/2 "2008-01-19T09:03:37Z")

</div>

In ur new action initialize that attribute to whatever value u wish.  
Check the docs it may have an option to set a default value.

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [March 3, 2008, 1:17pm UTC](https://www.ruby-forum.com/t/selecting-a-default-value-in-select-helper-method/126531/3 "2008-03-03T13:17:30Z")

</div>

On Jan 19, 1:02 pm, Bcp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In ur new action initialize that attribute to whatever value u wish.  
> Check the docs it may have an option to set a default value.
> 
> Sent from my iPhone
> 
> On Jan 18, 2008, at 5:05 PM, partydrone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi,

Even when this value is set in the action, first element in the select  
list is populated by default when the html is rendered.

Regards,  
HAK

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [March 3, 2008, 1:34pm UTC](https://www.ruby-forum.com/t/selecting-a-default-value-in-select-helper-method/126531/4 "2008-03-03T13:34:30Z")

</div>

partydrone wrote:

> How do I select a default value in a blank form when using select vs  
> select\_tag?

select is designed to choose a particular value for an attribute of an  
object. The call is:

select object, method, choices, options, html\_options

The given method on the given object is called and the item from the  
choices that matches (if any) will be selected.

If this is for a create form, then set the new object’s attribute to the  
initial default you want in your method:

def new  
@item = Item.new  
@item.state = default\_state\_value  
end

Then, in the view:

\<%= select :item, :state, …
