Form.select undefined method

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,
Order::PAYMENT_TYPES,
: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:


18:


19: Pay with:
20: <%= form.select :paytype,
21: Order::PAYMENT_TYPES,
22: :prompt => “Select a payment method”
%>
23:

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…

On 3 Apr 2008, at 11:54, Emanuele B. wrote:

        Order::PAYMENT_TYPES,

17:


18:


19: Pay with:
20: <%= form.select :paytype,
21: Order::PAYMENT_TYPES,
22: :prompt => “Select a payment method”
%>
23:

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

Fred

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

On 3 Apr 2008, at 12:05, Emanuele B. wrote:

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

Fred

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

On Apr 3, 6:42 am, Frederick C. [email protected]