Unknown (not mentioned) method

Dear all,

I’m happily coding through the book (bottom of page 106) and ran into a
“NoMethodError” (again).

NoMethodError in Store#checkout
Showing app/views/store/checkout.rhtml where line #22 raised:
undefined method `pay_type' for #<Order:0x408ba4d0>

Extracted source (around line #22):

19: 		<td>Pay using:</td>
20: 		<td><%=
21: 			options = [["Select a payment option", ""]] + 

Order::PAYMENT_TYPES
22: select(“order”, “pay_type”, options)
23: %>
24:
25:

There is indeed no method of the name “pay_type”, and the book doesn’t
mention it. Actions taken so far:

  • I’ve grepped on al downloaded rails-code sources. (not in there)
  • Created an empty one in store_controller.rb. (doesn’t seem to notice
    it).
  • When removing the above mentioned option line I don’t get that error.
    (it’s
    definitely the one that causes it).

What am I missing, or lacks in my Rails knowledge?

Thanx a lot for helping out a Rails newby!!

Regards,

Gerard.


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!

Dear all,

This one is a typo in the book, and will probably be submitted to the
online
errata.

The typo:

21: options = [[“Select a payment option”, “”]] + Order::PAYMENT_TYPES
22: select(“order”, “pay_type”, options)

→ the word “order” in the 2nd line should be “Order”.

For other newbies on Ruby on Rails:

The book:
http://pragmaticprogrammer.com/titles/rails/index.html

The Errata:
Pragmatic Bookshelf: By Developers, For Developers

Thanx and Greetz

Gerard.

On Tuesday 29 November 2005 11:54, Gerard tried to type something like:

Gerard.


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;
~
:wq!

Gerard wrote:

–> the word “order” in the 2nd line should be “Order”.

It’s “order” in my copy, and it works.

Aren’t you using “order” in the other form controls?
e.g.
text_field(“order”, “name”, “size” => 40 )

With respect to the NoMethodError, Rails should be providing
a “magic” pay_type accessor method, because you should have
a pay_type column in your orders table:

create table orders (
id int not null auto_increment,
name varchar(100) not null,
email varchar(255) not null,
address text not null,
pay_type char(10) not null,
shipped_at datetime null,
primary key (id)
);

(You may not have the shipped_at column yet - it gets added later in the
book)

Your checkout method should be creating a new Order and assigning it
to the instance variable @order

 @order = Order.new

and when Rails renders the checkout.rhtml page, the controls (referring
to it as “order”) are picking up the contents of that Order via its
“magic” accessor methods.

Since the payment type select control is the first to complain, I
suspect that the pay_type column is missing or mistyped in your table
definition.

See figure 17.2 in the book (it’s on page 342 in the PDF) for a clear
picture of how all the pieces fit together.

regards

Justin