0

I have created a basic Rails project called Book_shelf. It contains a controller called home. Inside the home controller I have defined an action called index. But when I try to run this application in the browser it gives me a routing error.

I am using this url to type in the browser: http://localhost:3000/home/index

Thanks,

ilya
  • 1
  • Have you checked routes.rb to make sure that there is a route for your controller? – Platinum Azure Aug 25 '11 at 19:34
  • what exactly is the error message you are getting? How are you starting your sever and what does the sever window show when the web page gets the error. – Michael Durrant Aug 25 '11 at 19:36
  • My routes.rb file is as follows: BookShelf::Application.routes.draw do root :to => "home#index" end – ilya Aug 27 '11 at 11:16
  • When I try to run this application using "rails server" command it gives me with the error: Routing error (no route matches "/home" ) – ilya Aug 27 '11 at 11:26

2 Answers2

0

Just a quickie before the answer , As per Rails convention controller names must be plural please ref :Singular or plural controller and helper names in Rails

Assuming that the controller name is homes_controller.rb in routes.rb add a route says resources :homes, if you do a scaffold routes will be added by the generators

Step 1: Please look out for the available routes by rake routes, you might get up like

Prefix Verb URI Pattern Controller#Action homes GET /homes(.:format) homes#index POST /homes(.:format) homes#create new_home GET /homes/new(.:format) homes#new edit_home GET /homes/:id /edit(.:format) homes#edit home GET /homes/:id(.:format) homes#show PATCH /homes/:id(.:format) homes#update PUT /homes/:id(.:format) homes#update DELETE /homes/:id(.:format)
You can find the controller and its mapped action.

Step 2: You can directly access index action, http://localhost:3000/homes ('/index') is default

ref: homes GET /homes(.:format) homes#index
Step 3: (if above doenst work) You can backtrace the error from the live termination on the browser if the problem persist when using Rails4

Community
  • 1
  • 1
0

The index action for home is by default located at http://localhost:3000/home/, there is no need to write index after that.

If you type index, rails assumes you are trying to use the show action for a home with an id of index, which of course will not exist since by default ids will be numbers.

ankit
  • 3,328
  • 3
  • 26
  • 39