small medium large xlarge

Generic-user-small
19 May 2010, 22:55
Stuart Cullum (2 posts)

I get:

NameError in Line itemsController#create

undefined local variable or method `product_id’ for #

app/controllers/line_items_controller.rb:45:in `create’

Not sure where I’ve gone wrong. Any ideas?

Many thanks, s.

Samr_small_pragsmall
20 May 2010, 11:42
Sam Ruby (634 posts)

On page 124, you added a line to the line_items_controller. That line is supposed to reference the id attribute of the product you just found. Perhaps instead of typing product.id (with a dot), you entered product_id (with an underscore)?

Generic-user-small
20 May 2010, 20:42
Stuart Cullum (2 posts)

Ahh! … Thanks for your time Sam.

s.

Davestys_10_optimized_bigger_pragsmall
05 Jul 2010, 21:02
David Stys (2 posts)

Hi Sam,

Loving the book so far, but just got stuck on page 121 of b5_0.pdf

Similarly to the previous post: When I click on my new “Add to Cart” button, I get the following error:

ArgumentError in Line itemsController#create

wrong number of arguments (0 for 1) Rails.root: /Users/dstys/Sites/work/depot

Application Trace | Framework Trace | Full Trace app/models/cart.rb:2 app/controllers/application_controller.rb:7:in current_cart' app/controllers/line_items_controller.rb:51:in create’ Request

Parameters:

{“product_id”=>”2”, “authenticity_token”=>”NnhbaGSOoKuJsEn0ccGUHbJp/vclIv4vFz7t/MOGGCo=”} Show session dump

Any help would be fantastic - thanks!

Dave

Davestys_10_optimized_bigger_pragsmall
05 Jul 2010, 23:26
David Stys (2 posts)

Aha! Finally - comparing enough files to your source, I found my problem…

I had the following typo in my cart model… has_many :line_items, :dependent => destroy

Which needs to be: has_many :line_items, :dependent => :destroy

(Notice, the “:” was missing at my destroy dependency…)

Thanks – I’m enjoying your book tremendously. I’m VERY new to Ruby and new to Rails, but I’m catching on fairly quickly. The book is easy to follow.

Dave

Generic-user-small
23 Jul 2011, 11:25
Steve Chen (2 posts)

Thank you David Stys. I made the exact mistake… couldn’t figure it out for days… the error message certain didn’t help…

Generic-user-small
07 Jul 2012, 13:57
Jack Sutherland (1 post)

Wow! David, I just pulled my hair out for the last 2 hours trying to figure this out. Glad I found your comment.

You must be logged in to comment