11 Jun 2010, 03:16
Generic-user-small

Melanie Young (1 post)

I am working through the depot application. In this section, there is suddenly a mention of app/controllers/line_items_controller, but there is no link to download this file. I found links to this file later in the text, but I am not sure I have what I need. If I include the line

<%= button_to 'Add to Cart', line_items_path(:product_id => product) %>

in views/store/index.html.erb, I get the error

undefined method `line_items_path’

What am I missing?

11 Jun 2010, 20:24
Samr_small_pragsmall

Sam Ruby (584 posts)

@Undefined method line_items_path@ from within a view would indicate that @resources :line_items@ is not present in @config/routes.rb@. That line is put into @config/routes.rb@ by

rails generate scaffold line_item product_id:integer cart_id:integer

If that line is present, one possibility that I haven’t seen since the Rails 2 days is that you need to restart your server in order to get this to be picked up.

15 Jun 2010, 04:14
Generic-user-small

Ken Foust (5 posts)

I can’t pass the test rake test:functionals rake test:functionals (in /Users/fousto/Projects/RubyProjects/depot) Loaded suite /Users/fousto/.rvm/gems/ruby-1.9.2-head/gems/rake-0.8.7/lib/rake/rake_test_loader Started …..E.E………….. Finished in 0.549209 seconds.

1) Error: test_should_show_cart(CartsControllerTest): ActionView::Template::Error: undefined method `line_items’ for #

localhost 3000 works but when I click on the cart button then

undefined method `line_items’ for # Rails.root: /Users/fousto/Projects/RubyProjects/depot

Application Trace | Framework Trace | Full Trace app/controllers/line_items_controller.rb:53:in `create’ Request

Parameters:

{“authenticity_token”=>”xU27hSB4zM6/NX8c1cvQ64txEi4NFYTjWbTy68LW4yU=”, “product_id”=>”3”}

15 Jun 2010, 12:48
Samr_small_pragsmall

Sam Ruby (584 posts)

Ken, please verify that app/models/cart.rb has the following line:

  has_many :line_items
15 Jun 2010, 16:31
Generic-user-small

Ken Foust (5 posts)

Sam thank you very much that got me through the testing phase - now on to the good stuff.

27 Aug 2013, 23:09
Generic-user-small

Andy Schroeder (1 post)

Note that I am following this demo with rails 4.0.0 and Ruby 2.0.0 and had to restart the server to get the change to take.

  You must be logged in to comment