Forum: Ruby on Rails Easy one

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.
rails.impaired (Guest)
on 2007-04-04 08:30
(Received via mailing list)
I have the following piece of code in an app:

    @states = LookupValue.find(:all,
                                :conditions => ['record_type = ?',
'STATE'],
                                :order => "char_value_1").map {|u|
[u.char_value_1, u.id] }


This builds a list of codes and descriptions from a common values
table.  The values are used in a "select" on a page.  The page works
fine, however, we would like to have an empty <option> inserted at the
beginning of the list to force the user to actually select an item
from the list.  Any suggestions how I can insert an empty/blank code/
description to @states ??

Thanks,

rails.impaired
Justin M. (Guest)
on 2007-04-04 08:38
rails.impaired wrote:
> I have the following piece of code in an app:
>
>     @states = LookupValue.find(:all,
>                                 :conditions => ['record_type = ?',
> 'STATE'],
>                                 :order => "char_value_1").map {|u|
> [u.char_value_1, u.id] }
>
>
> This builds a list of codes and descriptions from a common values
> table.  The values are used in a "select" on a page.  The page works
> fine, however, we would like to have an empty <option> inserted at the
> beginning of the list to force the user to actually select an item
> from the list.  Any suggestions how I can insert an empty/blank code/
> description to @states ??
>
> Thanks,
>
> rails.impaired

select("something", "something_id", @states, { :include_blank => true })

read more here
http://api.rubyonrails.org/classes/ActionView/Help...
This topic is locked and can not be replied to.