09 Nov 2013, 04:25
Generic-user-small

Jon Waite (2 posts)

Trying to run through the book in Rails 4.0.1, hitting a problem in Chapter 10 Task E (A Smarter Cart) pp 126.

Attempting to access a non-existent cart (e.g. http://localhost:3000/carts/wibble) gives:

NameError in CartsController#show undefined local variable or method ‘store_url’ for #<CartsController:0x(session ID)>

and points to the following line in app/controllers/carts_controller.rb as the source:

redirect_to store_url, notice: 'Invalid cart'

How/where should ‘store_url’ be defined? The routes.rb contains (at this point in my depot app):

get "store/index"
resources :carts
resources :products
resources :line_items
root 'store#index'

Many thanks in advance, Jon.

09 Nov 2013, 04:23
Generic-user-small

Jon Waite (2 posts)

I found that changing to the following in app/controllers/carts_controller.rb lets the invalid cart code work correctly, can’t help thinking that there’s something wrong in the routing at this point in the depot app (at least on Rails 4.0.1). Note the change from ‘store_url’ to ‘store_index_url’:

def invalid_cart
      logger.error "Attempt to access invalid cart #{params[:id]}"
      redirect_to store_index_url, notice: 'Invalid cart'
end
  You must be logged in to comment