Вопрос

I have a nested resource defined in routes.db:

resources :accounts do
  resources :transactions do 
end

I would like to create a route that is similar to 'new', but the action would be new_transfer, which would allow me to handle a special type of new transaction:

new_account_transaction GET    /accounts/:account_id/transactions/new(.:format)      transactions#new

I tried to define the resource including a method definition:

resources :accounts do
    resources :transactions
    member do 
      get 'new_transfer'
    end
end

or

resources :accounts do
   resources :transactions do 
      member do 
         get 'new_transfer'
      end      
   end
end

but I get:

new_transfer_account GET    /accounts/:id/new_transfer(.:format)                  accounts#new_transfer

or

new_transfer_account_transaction GET    /accounts/:account_id/transactions/:id/new_transfer(.:format) transactions#new_transfer

The second one is close, but I think it really should be transactions/new_transfer. If this is the best I can do, I then could not find the path that would satisfy to create a new link.

Any help would be appreciated.

Also tried adding a specific match. What would be the link_to for this route?

match '/accounts/:account_id/transactions/new_transfer', to: 'transactions#new_transfer'

/accounts/:account_id/transactions/new_transfer(.:format) transactions#new_transfer
Это было полезно?

Решение

Have you tried the match method for the routes?

Their example on Rails Guides:

match "/patients/:id" => "patients#show"

Hope this helps!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top