Forum: Ruby select()

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.
9aa1e92a0ebb17fdaad2fa39b4c52b8a?d=identicon&s=25 misiek (Guest)
on 2006-02-25 00:20
(Received via mailing list)
I got for now this code html

<select name="visible">
     <option value="1" selected="selected">Yes</option>
     <option value="0">No</option>
  </select> display

I need to transfer this code to ruby
some like =>

<%= select("property", "location_id",Location.find(:all, :conditions =>
"name != '' ").collect {|p| [p.name, p.id]}, { :include_blank => false
}) %>

function above look for from database some data and put it into the drop
box fields
I need display only YES and NO and set them values 0 and 1

any ideas ?
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2006-02-25 00:26
(Received via mailing list)
misiek wrote:
> <%= select("property", "location_id",Location.find(:all, :conditions
> => "name != '' ").collect {|p| [p.name, p.id]}, { :include_blank =>
> false }) %>
>
> function above look for from database some data and put it into the
> drop box fields
> I need display only YES and NO and set them values 0 and 1
>
> any ideas ?
>

Have you looked at erb
(http://ruby-doc.org/stdlib/libdoc/erb/rdoc/index.html) or the CGI
standard library
(http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html)?

Or do you mean parsing the HTML and making into that code?

-Justin
573b9499030e1ccb867ef80f0ff1ac49?d=identicon&s=25 Justin Bailey (Guest)
on 2006-02-25 01:11
(Received via mailing list)
Go to http://api.rubyonrails.com/ and click on the Method named
"collection_select". It does just what you want.
9539774fe19b5268e39ee6cf3ca19b71?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-02-25 07:07
(Received via mailing list)
Why not use a check box?  I always hated drop downs for binary state
variables.

_Kevin
This topic is locked and can not be replied to.