在Rails 3中重命名名为helper的自定义成员路由

时间:2012-03-15 00:25:40

标签: ruby-on-rails-3 routes

我列出的路线如下

resources :jobs do
  resources :invoices, :only => [:show] do
    get 'submit_invoice', :on => :member
  end
end

所以中间路线会创建一个像/jobs/:job_id/invoices/:id/submit_invoice这样的网址,这正是我想要的。但是,rails将名称submit_invoice_job_invoice分配给难以输入的路径。

如何才能使名称submit_invoice成为submit_invoice_pathsubmit_invoice_url

2 个答案:

答案 0 :(得分:4)

答案应该是:

get "/jobs/:job_id/invoices/:id/submit_invoice" => "invoices#submit_invoice", 
:as => "submit_invoice"

答案 1 :(得分:-2)

resources :jobs do
  resources :invoices, :only => [:show] do
    get 'submit_invoice', :on => :member, :as => 'submit_invoice'
  end
end

使用:as => 'routename'并将其作为routename_path调用。

:)