RoR - index method in controller
I'm getting this error for the URL http://localhost:3000/dashboard/
Routing Error No route matches "/dashboard"
but http://localhost:3000/dashboard/index works correct
How can i make all the below URLs works and shows the same view views/dashboard/index.html.erb
http://localhost:3000
http://localhost:3000/
http://localhost:3000/dashboard
http://localhost:3000/dashboard/
http://localhost:3000/dashboard/index
My routes file is
Mytest::Application.routes.draw do
get "dashboard/index"
root :to => "dashboard#index"
end
My controller file is
class DashboardController < ApplicationController
def index
end
end
Mytest::Application.routes.draw do
match "/dashboard", :to => 'dashboard#index'
root :to => "dashboard#index"
end
You can also add generic routes of /:controller/:action/:id(.:format)
style.
I would do
map.root :controller => "dashboard", :action => "index"
map.dashboard "/dashboard", :controller => "dashboard", :action => "index"
map.connect "/dashboard/:action", :controller => "dashboard", :action => "index"
#standard routes
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
Or you could make it more standard
#special case
map.root :controller => "dashboard", :action => "index"
#general case
map.connect ":controller", :action => "index"
map.connect ":controller/:action"
#standard routes
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
match '/dashboard', :controller => 'dashboard', :action => 'index'
Perhaps? I've not tested this though.
精彩评论