Selecting a default value in select helper method

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.

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.

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

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, ...