我遇到了创建正确路线的问题。我想传递我正在处理的元素的id,但它看起来不正确。
我的路线看起来像
resources :accounts
match 'account-audit' => 'accounts#audited',:as => :accountaudit
当我做rake路线时,我得到了
accounts GET /accounts(.:format) accounts#index
POST /accounts(.:format) accounts#create
new_account GET /accounts/new(.:format) accounts#new
edit_account GET /accounts/:id/edit(.:format) accounts#edit
account GET /accounts/:id(.:format) accounts#show
PUT /accounts/:id(.:format) accounts#update
DELETE /accounts/:id(.:format) accounts#destroy
accountaudit /account-audit(.:format) accounts#audited
当我转到页面链接看起来
本地主机:3000 /帐户audit.3
它应该看起来像
本地主机:3000 /帐户/ 3 /审计
如何让我的路线做我需要做的事情?
答案 0 :(得分:0)
您需要声明这样的路线
resources :accounts do
get :audit, on: :member, as: :accountaudit
end
这将生成localhost:3000/accounts/account_id/audit
之类的链接。检查this stackoverlfow question以了解成员和收集路线。
答案 1 :(得分:0)
您尝试做的是嵌套路线,这将为您提供帐户内审核的宁静路线
resources :accounts do
resources :audit
end