# form.select undefined method

**URL:** <https://discuss.rubyonrails.org/t/form-select-undefined-method/27496>\
**Category:** rubyonrails-talk\
**Created:** [April 3, 2008, 10:54am UTC](https://discuss.rubyonrails.org/t/form-select-undefined-method/27496 "2008-04-03T10:54:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 3, 2008, 10:54am UTC](https://discuss.rubyonrails.org/t/form-select-undefined-method/27496/1 "2008-04-03T10:54:21Z")

</div>

Hello to all! I'm new on this forum, and i'm getting started in Ruby on Rails 2.0. I'm following the tutorial on AWDWR, and i found this error i can't solve: I've this code for a type="select" field in a form wrapped in the form\_for helper. In the Order model i've the definition of PAYMENT\_TYPES:

form.select :pay\_type, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order::PAYMENT\_TYPES, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:prompt =\> "Select a payment method"

then, when i run my page, it shows this error message:

Showing store/checkout.html.erb where line #20 raised:

undefined method `paytype' for #\<Order:0x34ba82c\>

Extracted source (around line #20):

17: \</p\> 18: \<p\> 19: \<label for="order\_pay\_type" \>Pay with:\</label\> 20: \<%= form.select :paytype, 21: Order::PAYMENT\_TYPES, 22: :prompt =\> "Select a payment method" %\> 23: \</p\>

then, if i define a method called pay\_type in the Order model, it works, but i feel like there's something wrong because in the tutorial it never mentions to use this "pay\_type" method. Then, when i implement other functions involving this form, it shows many times this error about "undefined method 'pay\_types'", also if it's declared...

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 3, 2008, 11:00am UTC](https://discuss.rubyonrails.org/t/form-select-undefined-method/27496/2 "2008-04-03T11:00:24Z")

</div>

Does your order has a field called pay\_type or paytype ? The first parameter to form.select should match that.

Fred

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 3, 2008, 11:05am UTC](https://discuss.rubyonrails.org/t/form-select-undefined-method/27496/3 "2008-04-03T11:05:26Z")

</div>

> Does your order has a field called pay\_type or paytype ? The first parameter to form.select should match that.
> 
> Fred

No, i followed the tutorial and it never create a field called pay\_type in the Order model...i show you the Order model in the book:

class Order \< ActiveRecord::Base has\_many :line\_items PAYMENT\_TYPES = [# Displayed stored in db [ "Check" , "check"], ["Credit card" , "cc"], ["Purchase order" , "po"] ] # ... validates\_presence\_of :name, :address, :email, :pay\_type validates\_inclusion\_of :pay\_type, :in =\> PAYMENT\_TYPES.map {|disp, value\> value} # ... def add\_line\_items\_from\_cart(cart) cart.items.each do |item| li = LineItem.from\_cart\_item(item) line\_items \<\< li end end

The only things that match with pay\_type is a filed in the table orders in the DB

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 3, 2008, 11:42am UTC](https://discuss.rubyonrails.org/t/form-select-undefined-method/27496/4 "2008-04-03T11:42:03Z")

</div>

> > Does your order has a field called pay\_type or paytype ? The first parameter to form.select should match that.
> > 
> > Fred
> 
> No, i followed the tutorial and it never create a field called  
> pay\_type in the Order model...i show you the Order model in the book:

You say below that you've got one in the orders table. that's the same  
thing.

Fred

---

<div class="post-metadata">

**Author:** ![Kyle3](https://avatars.discourse-cdn.com/v4/letter/k/54ee81/32.png) [@Kyle3](https://discuss.rubyonrails.org/u/Kyle3)\
**Post date:** [April 3, 2008, 7:05pm UTC](https://discuss.rubyonrails.org/t/form-select-undefined-method/27496/5 "2008-04-03T19:05:40Z")

</div>

Emanuele,

I'm looking at AWDwRoR 2nd Ed. on page 131 (printed version), and at the top of the next page, you do create a pay\_type column in the orders table (after running the migration).

If you're using form\_for, your form objects must map to a model. That's why you got the error before you had a pay\_type column in your orders table. You shouldn't have to specifically define pay\_type in the model if it's in the database.

PAYMENT\_TYPES should be defined in the order model as an array of arrays:

PAYMENT\_TYPES = [["Check", "check"], ["Credit Card", "cc"], ["Purchase Order", "po"]]

These are merely drawn upon as the options for select - the first value is displayed in the form, and the second value is stored in the database. Do not confuse this with the pay\_type column in the database.

Also, as Fred pointed out, make sure that you're consistent in your use of pay\_type, not paytype or pay\_types. You'll definitely get errors if they don't all match.

-Kyle
