small medium large xlarge

21 Mar 2011, 12:09
Jonathan Childress (3 posts)

On page 136 is the line for dealing with an invalid cart ID: redirect_to store_url, :notice => 'Invalid cart'

However, when an invalid cart ID is put in the URL bar, I get undefined local variable or method store_url’ for #`

My config/routes.rb contains the line get "store/index" so I can’t figure out what the problem might be. Anybody else having this issue?


21 Mar 2011, 12:27
Jonathan Childress (3 posts)

Here’s the output of @rake routes@:

line_items GET    /line_items(.:format)          {:action=>"index", :controller=>"line_items"}
               POST   /line_items(.:format)          {:action=>"create", :controller=>"line_items"}
 new_line_item GET    /line_items/new(.:format)      {:action=>"new", :controller=>"line_items"}
edit_line_item GET    /line_items/:id/edit(.:format) {:action=>"edit", :controller=>"line_items"}
     line_item GET    /line_items/:id(.:format)      {:action=>"show", :controller=>"line_items"}
               PUT    /line_items/:id(.:format)      {:action=>"update", :controller=>"line_items"}
               DELETE /line_items/:id(.:format)      {:action=>"destroy", :controller=>"line_items"}
         carts GET    /carts(.:format)               {:action=>"index", :controller=>"carts"}
               POST   /carts(.:format)               {:action=>"create", :controller=>"carts"}
      new_cart GET    /carts/new(.:format)           {:action=>"new", :controller=>"carts"}
     edit_cart GET    /carts/:id/edit(.:format)      {:action=>"edit", :controller=>"carts"}
          cart GET    /carts/:id(.:format)           {:action=>"show", :controller=>"carts"}
               PUT    /carts/:id(.:format)           {:action=>"update", :controller=>"carts"}
               DELETE /carts/:id(.:format)           {:action=>"destroy", :controller=>"carts"}
   store_index GET    /store/index(.:format)         {:controller=>"store", :action=>"index"}
      products GET    /products(.:format)            {:action=>"index", :controller=>"products"}
               POST   /products(.:format)            {:action=>"create", :controller=>"products"}
   new_product GET    /products/new(.:format)        {:action=>"new", :controller=>"products"}
  edit_product GET    /products/:id/edit(.:format)   {:action=>"edit", :controller=>"products"}
       product GET    /products/:id(.:format)        {:action=>"show", :controller=>"products"}
               PUT    /products/:id(.:format)        {:action=>"update", :controller=>"products"}
               DELETE /products/:id(.:format)        {:action=>"destroy", :controller=>"products"}
          root        /(.:format)                    {:controller=>"store", :action=>"index"}

No route is present for /store, only /store/index. I haven’t a clue why.

21 Mar 2011, 12:30
Jonathan Childress (3 posts)

Added a line to @config/routes.rb@ to circumvent the issue, but it seems unnecessary in a COC framework:

match 'store' => 'store#index'
23 Mar 2011, 13:45
Steve Castaneda (11 posts)

How are you mapping the resources for :store in your routes.rb? The match parameter you added will do the trick, but I’m curious as to why it was mapping store_index vs just finding index at /store.

02 May 2011, 04:32
dave buenconsejo (1 post)

What is the difference between match ‘store’ => ‘store#index’ and get “store/index”, :as => ‘store’ ?

since both of mapping works, i guess mapping regular routes in rails 3 convention is something like match ‘store’ => ‘store#index’. In routes config i found sample of regular route. # Sample of regular route: # match ‘products/:id’ => ‘catalog#view’ # Keep in mind you can assign values other than :controller and :action

I just want second opinions. Thanks!

12 Mar 2012, 02:54
Michael Berrow (6 posts)

In routes.rb I found that I had to change

root to: 'store#index to
root to: 'store#index', as: 'store'

I am running Rails 3.1.1

You must be logged in to comment