Take a forum system, hypothetically. You have topics and posts  
controllers which both contain the 7 default RESTful actions. Then you  
realise "Oh, I want to add in a functionality that allows me to split  
topics based on the positioning of certain posts". Ah! A conundrum! So  
what do you do and where do you put it?

Well, since you're going to be splitting a *topic* based on *certain  
posts* I would put this functionality not in the topics controller,  
but the posts controller. The reason for this is because most likely  
we're going to want to split a topic based on a particular post. How  
we split it isn't really important right now. So we create a new  
action called split in our posts controller which has two ways of  
operating, first it will prompt a user how to split a post and then  
it'll undertake the task. So firstly we add it to our routes.rb file:

map.resources :posts, :member => { :split => [:get, :post] }

Notice how we're specifying the :member option here, signifying we  
only want a single post and then after that specifying an array of  
methods that our action will respond to.

When we click the link to go to this split we'll assume that the user  
gets prompted with a form on how they want to split the post (like, do  
they want to split the topic with all the posts after this post,  
before this post and if the new topic should include the post that is  
our candidate) and then when they submit this form it undertakes the  
actual splitting.

Now that's (what I'd like to think of as a) good example of adding a  
"RESTful" action that's not one of "The Seven" to your controller.

A bad example would be going into the topics controller and adding  
actions such as new_post, create_post, edit_post, etc. because post is  
its own resource. The creation, listing, showing, editing and  
destroying of separate resources should be kept separate.

Just a short description :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to