我列出的路线如下
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_path
和submit_invoice_url
?
答案 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
调用。
:)