small medium large xlarge

Generic-user-small
20 Mar 2011, 16:14
Jason Kellie (3 posts)

Hello,

I have apparently done something wrong but despite repeated attempts to locate the issue I am at a loss. I’ve just completed the edit to the show.html.erb file as written on page 132 (and of course everything up to that point) and I’m getting the following error:

NoMethodError in Line itemsController#create

Attempt to call private method

Rails.root: /Users/jkellie/sandbox/depot
Application Trace | Framework Trace | Full Trace

app/controllers/line_items_controller.rb:46:in `create'

Being a total n00b I’ve got no clue where to look to find out what I’ve marked ‘private’ that I apparently shouldn’t have.

Can anyone give me some suggestions as to where I need to start looking?

Thank you!

  • Jason
Generic-user-small
20 Mar 2011, 16:31
Jason Kellie (3 posts)

It seems that the issue popped up after I changed line_items_controller create method from this line:

@line_item = @cart.line_items.build(:product => product)

to this line:

@line_item = @cart.add_product(product.id)

I don’t know if that helps… I did notice that it also happens to be line 46 as referenced in the error I got above.

Generic-user-small
10 Apr 2011, 17:54
Jason Kellie (3 posts)

Finally discovered my error. I added the def of add_product(product_id) and corresponding if/else statements outside of the Cart class in the cart.rb model. Made the edit and poof it’s working fine again. So my takeaway from this is that a def outside of a class is earmarked as a private method?

You must be logged in to comment