質問

I am having problems create the right route. I want to pass in the id of the element that i am working on but it does not look right.

my route looks like

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

and when i do rake routes i get

          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

when i go to the page the link looks

localhost:3000/account-audit.3

and it should look like

localhost:3000/account/3/audit

how do i make my route do what i need it to do?

役に立ちましたか?

解決 2

What it looks like you are trying to do is a nested routes this will give you the restful routes for audit inside of accounts

resources :accounts do
  resources :audit
end

他のヒント

You need to declare routes like this

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

This will generate links like localhost:3000/accounts/account_id/audit. Check this stackoverlfow question to learn about member and collection routes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top