U-L
U-L

Reputation: 2681

ruby on rails gives a No route matches error

I am following the example in the book "Agile web development with rails" and am stuck. Hoping to get some help here. I created the depot app and then scaffolded the product resource:

rails generate scaffold Product title:string description:text image_url:string price:decimal

All is good. I can hit "http://localhost:3000/products" and see the products with nice css as supplied by the book.

I did not touch the app for a couple of hours and decided to work through the example again. I can no longer hit the products page. I get the following error:

No route matches [GET] "/products"

I have not changed anything. The book suggested the I commit everything to git occassionally. I have retrieved back the last commit and still the same error. Other are also getting the same error and have the same question on stackoverflow, but I do not understand the answers.

Here are the files:

routes.rb
Depot::Application.routes.draw do
  resources :products

routes command:

rake routes
    products GET    /products(.:format)          products#index
             POST   /products(.:format)          products#create
 new_product GET    /products/new(.:format)      products#new
edit_product GET    /products/:id/edit(.:format) products#edit
     product GET    /products/:id(.:format)      products#show
             PUT    /products/:id(.:format)      products#update
             DELETE /products/:id(.:format)      products#destroy

Also tried restarting the server a couple of times. Same error. I am sure I have not changed anything. But being a complete newbie to rails, I could have done something by mistake. Thanks for your help.

Upvotes: 0

Views: 394

Answers (1)

ewiinnnnn
ewiinnnnn

Reputation: 995

Maybe you have another rails server instance running which is not the depot app. Try checking the rails server log on the terminal

The same problem like this thread, Why do I get a No Route Matches [GET] "/products" when the route exists?, ?

Upvotes: 1

Related Questions