Forum: Ruby on Rails Is there a list of html_options for the FormOptionsHelper?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cornelius B. (Guest)
on 2005-12-19 05:30
I'm looking for a way to select a default value from a select box, like

select("user", "role_id", Role.find_all.collect {|r| [, ] },
{ :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.


(2nd day on Rails, 1st post to the forum)
John W. (Guest)
on 2005-12-19 05:48
(Received via mailing list)
On 12/18/05, Cornelius B. <removed_email_address@domain.invalid> 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
    the object is available.


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
Rick O. (Guest)
on 2005-12-19 05:51
(Received via mailing list)
On 12/18/05, Cornelius B. <removed_email_address@domain.invalid> 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.

Cornelius B. (Guest)
on 2005-12-19 07:11
Thanks Rick, that did it!

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

In the 'Account/signup' controller, I put:

  @user =[:user])
  @roles = Role.find_all
  @user.role_id = '5'
This topic is locked and can not be replied to.