routing error in Ruby on Rails
I have created a basic Rails project called Book_shelf. It contains a controller called home. Inside the h开发者_JAVA技巧ome 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,
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.
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
精彩评论