在rails 3中创建特定的自定义路由

时间:2012-10-24 13:56:11

标签: ruby-on-rails ruby-on-rails-3 routing routes

我有几个级别的嵌套路由。

 resources :departments do
  resources :tasks do
    collection do
      get "report" => "tasks#report"
    end
 end

这是它的一部分。

我尝试做的是为report.html.erb文件创建自定义路由。但是,此路由创建路径/ department /:id / tasks / report

我想创建路径/ department /:id / tasks /:id / report

这可能吗?我考虑过为报告创建一个新的控制器和模型,但这似乎效率低下。

1 个答案:

答案 0 :(得分:1)

尝试:

resources :departments do
  resources :tasks do
    member do
      get "report" => "tasks#report"
    end
  end
end

或只是:

resources :departments do
  resources :tasks do
    get "report" => "tasks#report", :on => :member
  end
end