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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cd90f56139c1aa1ac7181eff418b10aa?d=identicon&s=25 Cornelius Bergen (corny)
on 2005-12-19 04:30
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)
10d9ed7ab11115b081bb36f56a7a13bc?d=identicon&s=25 John Wilger (Guest)
on 2005-12-19 04:48
(Received via mailing list)
On 12/18/05, Cornelius Bergen <cornelius@cbergen.com> 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/Help...

--
Regards,
John Wilger
http://johnwilger.com

-----------
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
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2005-12-19 04:51
(Received via mailing list)
On 12/18/05, Cornelius Bergen <cornelius@cbergen.com> 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
Cd90f56139c1aa1ac7181eff418b10aa?d=identicon&s=25 Cornelius Bergen (corny)
on 2005-12-19 06:11
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'
This topic is locked and can not be replied to.