2012-07-17 86 views
0

我遇到了问题,创建了正确的路线。我想传递我正在处理的元素的id,但它看起来不正确。创建一条简单的路线

我的路线看起来像

resources :accounts 
    match 'account-audit' => 'accounts#audited',:as => :accountaudit 

,当我做耙路线我得到

  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

是什么样子,你正在试图做的是一个嵌套的路线这会给你的帐户内审计的宁静路线

resources :accounts do 
    resources :audit 
end 
0

需要声明这样

resources :accounts do 
    get :audit, on: :member, as: :accountaudit 
end 

这将产生像localhost:3000/accounts/account_id/audit链接路线。查询this stackoverlfow question了解会员和收集路线。

+2

我是个肯定的作品,但我最终使用 '匹配“/ account /:id/audit'=>'accounts#audited',:as =>:accountaudit' – MZaragoza 2012-07-23 13:57:33