# Select()

**URL:** <https://rubytalk.org/t/select/25215>\
**Category:** ruby-talk\
**Created:** [24 February 2006 23:18 UTC](https://rubytalk.org/t/select/25215 "2006-02-24T23:18:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![misiek](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@misiek](https://rubytalk.org/u/misiek)\
**Post date:** [24 February 2006 23:18 UTC](https://rubytalk.org/t/select/25215/1 "2006-02-24T23:18:33Z")

</div>

I got for now this code html

\<select name="visible"\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="1" selected="selected"\>Yes\</option\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="0"\>No\</option\>  
&nbsp;&nbsp;\</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](http://p.name), [p.id](http://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 ?

---

<div class="post-metadata">

**Author:** ![Collins\_Justin](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@Collins\_Justin](https://rubytalk.org/u/Collins_Justin)\
**Post date:** [24 February 2006 23:23 UTC](https://rubytalk.org/t/select/25215/2 "2006-02-24T23:23:48Z")

</div>

misiek wrote:

> I got for now this code html
> 
> \<select name="visible"\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\<option value="1" selected="selected"\>Yes\</option\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\<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 ?

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

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

-Justin

---

<div class="post-metadata">

**Author:** ![BA\_Baracus](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@BA\_Baracus](https://rubytalk.org/u/BA_Baracus)\
**Post date:** [25 February 2006 06:07 UTC](https://rubytalk.org/t/select/25215/3 "2006-02-25T06:07:23Z")

</div>

Why not use a check box? I always hated drop downs for binary state  
variables.

\_Kevin

> **···**
>
> On Saturday, February 25, 2006, at 8:18 AM, misiek wrote:
> 
> > I need display only YES and NO and set them values 0 and 1
> > 
> > any ideas ?
> 
> --  
> Posted with [http://DevLists.com](http://DevLists.com). Sign up and save your time!

---

<div class="post-metadata">

**Author:** ![Justin\_Bailey](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Justin\_Bailey](https://rubytalk.org/u/Justin_Bailey)\
**Post date:** [25 February 2006 00:10 UTC](https://rubytalk.org/t/select/25215/4 "2006-02-25T00:10:08Z")

</div>

Go to [http://api.rubyonrails.com/](http://api.rubyonrails.com/) and click on the Method named  
"collection\_select". It does just what you want.

> **···**
>
> On 2/24/06, Justin Collins \<collinsj@seattleu.edu\> wrote:
> 
> > misiek wrote:  
> > \> 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 ?  
> > \>
> > 
> > Have you looked at erb  
> > ([http://ruby-doc.org/stdlib/libdoc/erb/rdoc/index.html\](http://ruby-doc.org/stdlib/libdoc/erb/rdoc/index.html%5C)) or the CGI  
> > standard library ([http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html\](http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html%5C))?
> > 
> > Or do you mean parsing the HTML and making into that code?
> > 
> > -Justin
