small medium large xlarge

Generic-user-small
02 Jun 2010, 15:01
Richard Schneeman (3 posts)

I’m working through the book right now, i’ve used rails for awhile, and wanted to check out the new edition. I may just be missing something simple but in Task G of the Atom Builder we call

products_controller.rb

@product = Product.find(params[:id])

who_bought.atom.builder

latest_order = @product.orders.sort_by(&:updated_at).last

Did we ever define a relationship between Product, and Order ? A product has many line_items, and an order belongs_to line_items, but it doesn’t look like we ever explicitly link order and product (i’m getting a no method error).

Please forgive me if this is something trivial, though i’m not able to find the linking code at this time.

Samr_small_pragsmall
02 Jun 2010, 21:20
Sam Ruby (634 posts)

No need to apologize, that was an oversight on my part. Add the following line to the top of app/models/product.rb:

has_many :orders, :through => :line_items

I’ll fix that in the next beta. Thanks!

Generic-user-small
02 Jun 2010, 21:38
Richard Schneeman (3 posts)

That looks better! Thanks for the update, it’s good to know i’m not going (completely) crazy.

Generic-user-small
02 Feb 2012, 15:40
djfox (9 posts)

Sam:

In the PDF, on page 229, do not understand if I have to create a file such as “builder” (who_bought.atom.@builder@) or is created only when typing “format.atom “,??, as if created by typing I think it is lacking a gem .. please help

Samr_small_pragsmall
02 Feb 2012, 17:54
Sam Ruby (634 posts)

@djfox: you need to create the file. Generate scaffold commands do a pretty good job of anticipating what files you may need, but there are still times when you need to create a file from scratch.

Generic-user-small
02 Feb 2012, 18:38
djfox (9 posts)

Ok thanks Sam!..i solved with you help!

You must be logged in to comment