Search code examples
ruby-on-railsroutesactivemerchantrailscastsnomethoderror

NoMethodError - undefined method in routes following Railscast 145


I'm using Rails 3.1 and following this railscast to implement active merchant, I'm trying to copy the shopping cart used in the episode but am getting this error:

NoMethodError

undefined method `current_cart' for # Rails.root: /users/dave/work/sell

Application Trace | Framework Trace | Full Trace config/routes.rb:7:in block (2 levels) in <top (required)>' config/routes.rb:6:inblock in ' config/routes.rb:1:in `' This error occurred while loading the following files:
/users/dave/work/sell/config/routes.rb

My Routes.rb

Sell::Application.routes.draw do

  resources :orders

  current_cart 'cart', :controller => 'carts', :action => 'show', :id => 'current'

  resources :line_items
  resources :carts    
  resources :products 
end

The rails cast version (from looking at the source on github) uses the |map| map.resources :whatever way of writing the routes.rb.

Thanks for any help its much appreciated!


Solution

  • Try change route like

    get 'cart' => 'carts#show', :as => 'current_cart'