# Controller best practices

**URL:** <https://discuss.rubyonrails.org/t/controller-best-practices/58893>\
**Category:** rubyonrails-talk\
**Created:** [May 10, 2011, 2:54pm UTC](https://discuss.rubyonrails.org/t/controller-best-practices/58893 "2011-05-10T14:54:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 10, 2011, 2:54pm UTC](https://discuss.rubyonrails.org/t/controller-best-practices/58893/1 "2011-05-10T14:54:06Z")

</div>

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 &nbsp;&nbsp;## lump everything into show? &nbsp;&nbsp;def show &nbsp;&nbsp;&nbsp;&nbsp;if params[:id] == "follow" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;users = current\_user.following &nbsp;&nbsp;&nbsp;&nbsp;elsif params[:id] == "follow\_me" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;users = current\_user.users\_who\_follow\_me &nbsp;&nbsp;&nbsp;&nbsp;elsif params[:id] == "following\_follow\_me" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;users = current\_user.following\_who\_follow\_me &nbsp;&nbsp;&nbsp;&nbsp;elsif params[:id] == "following\_who\_do\_not\_follow\_me" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;users = current\_user.following\_who\_do\_not\_follow\_me &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;respond\_with do |format| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.json do {...} &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

&nbsp;&nbsp;## or split everything out into separate methods, this requires additional routing &nbsp;&nbsp;def following &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;end

&nbsp;&nbsp;def users\_who\_follow\_me &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;end

&nbsp;&nbsp;def following\_who\_follow\_me &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;end

&nbsp;&nbsp;def following\_who\_do\_not\_follow\_me &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;end end

Everything in show
