doub1ejack
doub1ejack

Reputation: 11171

How to write rails route for /resource_1/{:id}/action/{:resource_2_id}?

I just introduced a join table to add Plants to Gardens and I'm trying to implement this in my first-ever rails app. I want to

Add a Plant to a Garden

This seems like a nice restful path: /plants/{id}/add_to_garden/{garden_id}, but I'm having trouble figuring out how to write that route.

This makes sense to me, but it doesn't work:

resources :plants do
    member do
      post 'add_to_garden/:garden_id'
    end
  end

Upvotes: 0

Views: 26

Answers (1)

David
David

Reputation: 3610

One possible way is:

post 'plants/:id/add_to_garden/:garden_id' => 'plants#add_to_garden', as: :add_to_garden

Upvotes: 1

Related Questions