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:
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...
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:
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.