如何自定义根路径的网址?

时间:2019-06-05 16:44:19

标签: ruby-on-rails routes

我当前的根目录以以下形式提供网址: www.project.com/taskforce

但我希望该网址为: www.project.com/taskforce/仪表板

我想我可以通过添加以下内容来实现: root to: "dashboard#index", path: "taskforce/dashboard"

但是出现以下错误: Ambiguous route definition. Both :path and the route path were specified as strings.

我的路线如下:

module TaskForceRoutes
  def self.extended(router)
    router.instance_exec do
      namespace :taskforce do
        root to: "dashboard#index"
        get :new_group_runners, to: "dashboard#new_group_runners", path: "new-group-runners"
        get :members_not_running_much, to: "dashboard#members_not_running_much", path: "members-not-running-much"
        get :attendance_stats, to: "dashboard#attendance_stats", path: "attendance-stats"
        get :area_heroes, to: "dashboard#area_heroes", path: "area-heroes"
        get :resign, to: "dashboard#resign", path: "resign"
      end
    end
  end
end

我有一个Taskforce :: DashboardController

1 个答案:

答案 0 :(得分:1)

尝试一下:

# routes.rb

scope 'taskforce/dashboard' do
  root to: "dashboard#index"
end

来源:https://guides.rubyonrails.org/routing.html