Is there a list of html_options for the FormOptionsHelper?

I’m looking for a way to select a default value from a select box, like
this:

select(“user”, “role_id”, Role.find_all.collect {|r| [ r.name, r.id ] },
{ :default_value => ‘5’ }

(of course, there is no “:default_value”)

If the form is being used on a ‘create’ page, it should display a
default in the select box. If the form is on the ‘edit’ page, it should
display the current value.

Thanks,
corny

(2nd day on Rails, 1st post to the forum)

On 12/18/05, Cornelius B. [email protected] wrote:

display the current value.
Assuming I’m understanding your question correctly, this should be
handled automatically by the #select method. According to the API
documentation [1]:

The option currently held by the object will be selected, provided 

that
the object is available.

[1]
http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000351


Regards,
John W.


Alice came to a fork in the road. “Which road do I take?” she asked.
“Where do you want to go?” responded the Cheshire cat.
“I don’t know,” Alice answered.
“Then,” said the cat, “it doesn’t matter.”

  • Lewis Carrol, Alice in Wonderland

On 12/18/05, Cornelius B. [email protected] wrote:

display the current value.
html_options are for attributes, like class.

select is one of the form helpers that uses ActiveRecord. The default
value is therefore whatever @user.role_id is. You should be able to
set it in the controller.


rick
http://techno-weenie.net

Thanks Rick, that did it!

John, if the object is NOT available I wanted to display a default
option.

In the ‘Account/signup’ controller, I put:

@user = User.new(@params[:user])
@roles = Role.find_all
@user.role_id = ‘5’