I'm frequently building controllers where i would like multiple methods (in addition to index, edit, show, etc.). Most of the time the actions i desire could be lumped into show as they are simple GET operations, however I don't want to put too much logic in any one controller action.
Here is a quick example of two different ways to achieve the same thing...
class TwitterFriendController < ApplicationController ## lump everything into show? def show if params[:id] == "follow" users = current_user.following elsif params[:id] == "follow_me" users = current_user.users_who_follow_me elsif params[:id] == "following_follow_me" users = current_user.following_who_follow_me elsif params[:id] == "following_who_do_not_follow_me" users = current_user.following_who_do_not_follow_me ... end respond_with do |format| format.json do {...} end end
## or split everything out into separate methods, this requires additional routing def following ... end
def users_who_follow_me ... end
def following_who_follow_me ... end
def following_who_do_not_follow_me ... end end
Everything in show