small medium large xlarge

Bog_mallaranny_pragsmall
31 Jan 2011, 14:20
Barry O'Gorman (3 posts)

Agile Web Development with Rails - 4th Edition

Pages 84/85:

I created a new application

railsdev> rails new depot

I set up the database using scaffold:

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

I completed the migration:

depot> rake db:migrate

depot> rails server

input: http://localhost:3000/Products

Getting Routing error No route matches “/Products”

Zim_pragsmall
02 Feb 2011, 23:21
Augusto Rodriguez (9 posts)

Hi Barry,

I had to run exactly the commands you posted to reproduce the error… just navigate to http://localhost:3000/products (all lower case) and voila.

I’m new to ruby too, so I’m trying to get used as much as I can with the errors. If you go to the incorrect url, you can see in the server logs

ActionController::RoutingError (No route matches “/Products”):

so the router (router.rb) couldn’t find a route to a controller named “Products”.

Cheers, Augusto

Bog_mallaranny_pragsmall
04 Feb 2011, 10:23
Barry O'Gorman (3 posts)

When I navigate to: http://localhost:3000/products I am still getting the same error. using lowercase does not seem to solve the problem.

Zim_pragsmall
04 Feb 2011, 14:02
Augusto Rodriguez (9 posts)

Hi Barry,

Can you paste your routes.rb (please remove all the comments from it :D) and the error you get in WebBrick?

Generic-user-small
06 Feb 2011, 23:27
Victor Yu (2 posts)

I got the same error as Barry and followed the tutorial exactly as he did. Here is a copy of the routes.rb file (the numbers are supposed to be “#” symbols):

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

# The priority is based upon order of creation: # first created -> highest priority.

# Sample of regular route: # match ‘products/:id’ => ‘catalog#view’ # Keep in mind you can assign values other than :controller and :action

# Sample of named route: # match ‘products/:id/purchase’ => ‘catalog#purchase’, :as => :purchase # This route can be invoked with purchase_url(:id => product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products

# Sample resource route with options: # resources :products do # member do # get ‘short’ # post ‘toggle’ # end # # collection do # get ‘sold’ # end # end

# Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end

# Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get ‘recent’, :on => :collection # end # end

# Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end

# You can have the root of your site routed with “root” # just remember to delete public/index.html. # root :to => “welcome#index”

# See how all your routes lay out with “rake routes”

# This is a legacy wild controller route that’s not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match ‘:controller(/:action(/:id(.:format)))’ end

Generic-user-small
07 Feb 2011, 05:39
Victor Yu (2 posts)

I figured out the solution to my problem after a few hours of google searching. The problem was that my Webrick server was running under the “>demo” directory, so all I did was restart the server under the “>depot” directory in the command line and the web page loaded fine after that. I hope this works for you too.

You must be logged in to comment