Rails combine member & collection in routes.rb

212 views Asked by At

I am trying to combine collection and member in the conversations path. But I could not figure it out,

resources :conversations, only: [:index, :show, :destroy] do

  member do
    post :reply
    post :restore
  end
end

and;

resources :conversations, only: [:index, :show, :destroy] do
  collection do
    delete :empty_trash
  end
end

When I combine them it does not work, and obviously this one is wrong too!.

2

There are 2 answers

0
jon snow On BEST ANSWER

Combine member and collection in resources block. Like this,

resources :conversations, only: [:index, :show, :destroy] do
  member do
    post :reply
    post :restore
  end
  collection do
    delete :empty_trash
  end
end

Or you may combine it like this also,

resources :conversations, only: [:index, :show, :destroy] do
  post :reply, on: :member
  post :restore, on: :member
  delete :empty_trash, on: :collection
end
0
Sachin R On

try this

resources :conversations, only: [:index, :show, :destroy] do
  member { 
    post :reply
    post :restore 
  }       
  collection {
     delete :empty_trash
  }   
end