Jason
Jason

Reputation: 397

Rails Routes vs URL parameters

I have a double headed question I hope you're able to help me with.

As a bit of context, I have a rails app with a Request model/controller/view setup. It is used for a user to send a request to another user and provides two specific facilities within the update action (trying to stay RESTful) - accept and decline (accept or decline the request).

So my questions are:

Upvotes: 2

Views: 923

Answers (1)

wanghq
wanghq

Reputation: 1356

I prefer /requests/11/accept to /requests/11?response=accept.

Accept and decline are behaviors that will change the state of request resource, so a PUT operation on a single object is appropriate.

You can define a route in your routes config, like below:

resources :requests do
  member {put :accept, :decline}
end

You will get two routes

accept_request maps to {:action=>"accept", :controller=>"requests"}
decline_request maps to {:action=>"decline", :controller=>"requests"}

Upvotes: 1

Related Questions