1

I have resources in routes file:

resources :forwardings

And I need to add the action which will save settings to all items in collection.

The question is which method should I use to implement this one?

resources :forwardings do
  put 'save_all', :on => :collection
  # or
  post 'save_all', :on => :collection
end

Maybe I'm missing some details and I'd glad to hear out. Thanks

megas
  • 21,401
  • 12
  • 79
  • 130

2 Answers2

3

You can use both, it doesn't matter, both are 'good' for creating.

Read more here: PUT vs POST in REST

Really look into those answers, there are many explanations.

Community
  • 1
  • 1
Zippie
  • 6,018
  • 6
  • 31
  • 46
0

PUT expects resource-ID in order to perform create/update operation and POST just create resource blindly. Or we can say that when posting data using POST then resource-ID is assigned by server after performing the requested operation so that using that resource-id further operation can be done. if we expect resource-id to be allocated from server side then we can use POST or if resource id is to be given by client then we can use PUT.

vivek
  • 1