Reading this: http://guides.rubyonrails.org/routing.html#adding-more-restful-actions
What does it mean to add a ‘member route’?
or do add a route to the collection?
What is a member and a collection when talking about routes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They’re both ways to add additional actions to a resource-based route in Rails.
I like to think of them in terms of RESTful URLs. Consider the basics for a resource/model
FooNotice how:
Member routes and collection routes let you add additional routes/actions using the same techniques as I listed above.
A member route adds a custom action to a specific instance using the URL suffix and HTTP method you provide. So, if you had a member route declaration of
:member => { :bar => :get }. you’d get an additional route of:Note how it overloads
GET /foo/:idin the same way that `edit’ does. This is how you’d implement a “delete” action that provides a UI for the “destroy” action.Similarly, a collection route adds an overload to the collection and/or a non-specific instance (it’s up to you to decide exactly what it implies). So, if you declared
:collection => { :baz => :get }, you’d get an additional route:…in very much the same way as
new.You can also customize the HTTP method.
For example, I just recently had a project where I needed a “reply” action on a
Comment. It’s basically the same idea asComment#create(which uses POST), except that it’s in reference to a specific parentComment. So, I created a member route::member => { :reply => :post }. This gave me:This keeps the routes restful while still expanding upon the basic 7 actions.