# Help with form\_for helper selects

**URL:** <https://www.ruby-forum.com/t/help-with-form-for-helper-selects/108076>\
**Category:** Rails\
**Created:** [June 28, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/help-with-form-for-helper-selects/108076 "2007-06-28T21:23:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CPerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@CPerry](https://www.ruby-forum.com/u/CPerry)\
**Post date:** [June 28, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/help-with-form-for-helper-selects/108076/1 "2007-06-28T21:23:31Z")

</div>

Hey all, I am building a form for my app and I am having some trouble  
with creating a select for the form.

In my form\_for helper, I am attempting to create a selection drop down  
and here is the code for that…

Is this pet Spayed/Neutered?  
 \<%= form.select(Yes,No) :fixed %\>

This obviously does not work, but I am not quite sure why it does not  
work. Could someone please post a basic example of a select for me, or  
help me with I am missing in my above code? I know that what is in the  
parenthesis is not right, but what is it missing?

Thanks!!

–Cory

---

<div class="post-metadata">

**Author:** ![CPerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@CPerry](https://www.ruby-forum.com/u/CPerry)\
**Post date:** [June 28, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/help-with-form-for-helper-selects/108076/2 "2007-06-28T21:47:35Z")

</div>

> This obviously does not work, but I am not quite sure why it does not  
> work. Could someone please post a basic example of a select for me, or  
> help me with I am missing in my above code? I know that what is in the  
> parenthesis is not right, but what is it missing?

Let’s pretend you have an instance of Pet in @pet and it has a “spayed”  
attribute.

You could then do:

form.select(“pet”, “spayed”, [[‘Yes’, true], [‘No’, false]])

Assuming @pet.spayed was a boolean field anyway.

Not sure what the :fixed option is, but there are additional arguments  
to  
the method for options and html\_options.

-philip

---

<div class="post-metadata">

**Author:** ![CPerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@CPerry](https://www.ruby-forum.com/u/CPerry)\
**Post date:** [June 28, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/help-with-form-for-helper-selects/108076/3 "2007-06-28T22:02:37Z")

</div>

The :fixed option relates back to the column in my table. Here is the  
entire form…

\<% form\_for :listing,  
:html =\> { :class =\> “new\_listing” } do |form| %\>

Title of listing:  
 \<%= form.text\_field :title %\>

Listing Category:  
 \<%= form.text\_field :listing\_type %\>

Breed of Pet:  
 \<%= form.text\_field :breed %\>

Gender of Pet:  
 \<%= form.select(Male,Female) :gender %\>

Age of Pet:  
 \<%= form.text\_field :age %\>

Is this pet Spayed/Neutered?  
 \<%= form.select(Yes,No) :fixed %\>

Quantity of Pets:  
 \<%= form.text\_field :quantity %\>

Where are you located?  
 \<%= form.text\_field :location %\>

Phone Number for Inquiries:  
 \<%= form.text\_field :phone %\>

Listing Description:  
 \<%= form.text\_area(:cols="20" :rows="20") %\>

\<%= submit\_tag %\>

\<% end %\>

I am sure there are some other little mistakes in there, the select  
was just the first one that popped up! My idea with the select was to  
have the user choose Yes or No, and that would then be stored in the  
table as a string. Not sure that this is the best way of accomplishing  
this, but it seemed to be the ideal situation given my extremely  
limited Rails knowledge! Thanks for any other help that you can  
provide.

–Cory

---

<div class="post-metadata">

**Author:** ![CPerry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@CPerry](https://www.ruby-forum.com/u/CPerry)\
**Post date:** [June 29, 2007, 12:13am UTC](https://www.ruby-forum.com/t/help-with-form-for-helper-selects/108076/4 "2007-06-29T00:13:59Z")

</div>

Am I correct in saying that as it stands now, with the form posted  
above, that the value of the select would be stored in the DB as a  
string? The column type that I set up in my migration file is a  
string. So I was thinking that their yes/no choice would be stored as  
a string when the form got submitted. Am I on the right track here?

–Cory
