开发者

RoR - index method in controller

I'm getting this error for the URL http://localhost:3000/dashboard/

Routing Error No route matches "/dashboard"

开发者_C百科

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜