# Skinny Controller, Fat View?

**URL:** <https://www.ruby-forum.com/t/skinny-controller-fat-view/171842>\
**Category:** Rails\
**Created:** [July 10, 2009, 1:25am UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842 "2009-07-10T01:25:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 10, 2009, 1:25am UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/1 "2009-07-10T01:25:15Z")

</div>

My Web application has several contexts where a collection of  
ActiveRecords is  
rendered. If the URL contained the partial and/or layout, the several  
controller methods could be collapsed into one. What hazards, etc. lie  
that  
way?

TIA,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 10, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/2 "2009-07-10T22:08:04Z")

</div>

2009/7/10 Jeffrey L. Taylor [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> My Web application has several contexts where a collection of ActiveRecords is  
> rendered. Â If the URL contained the partial and/or layout, the several  
> controller methods could be collapsed into one. Â What hazards, etc. lie that  
> way?

I, for one, do not understand what you mean. Could you give a more  
detailed description, with example?

Colin

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 10, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/3 "2009-07-10T23:41:02Z")

</div>

Quoting Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 

It’s an RSS readers. Users have feeds that have articles. A list of  
articles  
can appear in about four contexts: a paginated flat list of all unread  
articles, a flat list of articles found by a search. list of all unread  
articles indented under a feed (with collapse/expand icons), a list of  
all  
read articles under another type of header. Currently all of these have  
their  
own action method under two different controllers.

I think it is feasible to have one action method that is passed the  
selection  
criteria (unread, read, etc. articles) and a layout or partial template  
to  
render thru the URL. Beyond the obvious SQL injection protection and  
restricting the template/layout to a known set of reasonable values,  
what  
hazards (security, maintenance, etc.) lie this way?

I think I can move towards and possibly achieve a RESTful API with a bit  
of  
squeezing state and context into the URL.

Does this way lie madness/dragons?

TIA,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 11, 2009, 12:17am UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/4 "2009-07-11T00:17:24Z")

</div>

Work at implementing Helpers into your app. You can outline your  
pagination methods in many different helper models and keep things  
transparent on your views as well as make things more manageable for  
yourself.

For instance,

Let’s say you have a number of pagination views you are going to use for  
tables. Create a tables\_helper.rb file and place your pagination  
methods there that apply for table formatting etc.

Partials really only need to be created when you have multiple needs for  
the same bit of code between the views on a particular model. If you  
had 8 views for instance on one model and you are reusing a lot of the  
same code in those views, then create partials for the code bits you are  
sharing.

However, keep in mind that sometimes you may get things too messy in  
your partials, especially if you use javascript or are applying  
conditions. They can’t be readily checked unless you create controller  
methods that look into the specific partials as they are generated.

This is why I recommend (as far as pagination goes), use helpers. They  
make a world of difference.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 11, 2009, 12:59am UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/5 "2009-07-11T00:59:20Z")

</div>

Hello–

On Jul 10, 2009, at 2:40 PM, Jeffrey L. Taylor wrote:

> > > etc. lie that  
> > > articles indented under a feed (with collapse/expand icons), a list  
> > > restricting the template/layout to a known set of reasonable values,  
> > > Jeffrey  
> > > If you embed that information in the URL, you wouldn’t be the first  
> > > (nor probably the last) to do it, but you are then tying your URL to  
> > > your implementation. Littering URLs with implementation details can  
> > > break bookmarks and also be confusing to search engines, which may or  
> > > may not matter to you.

Why is the querystring not sufficient? E.g.  
[http://my.domain.com/keenview?view=flat](http://my.domain.com/keenview?view=flat)  
. That exposes a bit of the implementation but probably won’t break if  
the view key is left off.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 11, 2009, 4:17am UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/6 "2009-07-11T04:17:19Z")

</div>

Check out the Presenter pattern. This might help out a bit:

> **[Rails: Presenter Pattern](http://blog.jayfields.com/2007/03/rails-presenter-pattern.html)**
>
> The default architecture for Ruby on Rails, Model View Controller, can begin to break down as Controllers become bloated and logic begins to...

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 11, 2009, 1:48am UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/7 "2009-07-11T01:48:23Z")

</div>

Quoting s.ross [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > >
> > 
> > bit of  
> > break bookmarks and also be confusing to search engines, which may or  
> > may not matter to you.
> 
> Why is the querystring not sufficient? E.g. [http://my.domain.com/keenview?view=flat](http://my.domain.com/keenview?view=flat)  
> . That exposes a bit of the implementation but probably won’t break if  
> the view key is left off.

Most of these contexts are AJAX responses so bookmarkability is not  
relevant,  
but I will keep it in mind. In fact, search results are currently not  
bookmarkable because only POST requests are actually searches, any GET  
request  
to the URL is expected to be a pagination request. Thank you for  
pointing  
that out. Currently too much state is in the session, so not  
bookmarkable.

I will think on this,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [July 11, 2009, 4:37am UTC](https://www.ruby-forum.com/t/skinny-controller-fat-view/171842/8 "2009-07-11T04:37:10Z")

</div>

Several years ago when I first heard about the Presenter, it didn’t make  
sense. Unneeded complexity. But now maybe I’ve encountered the  
problem(s) it  
is a solution to. I’ll look at it.

Thanks,  
Jeffrey

Quoting s.ross [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > > > > rendered. If the URL contained the partial and/or layout, the  
> > > > > > can appear in about four contexts: a paginated flat list of all  
> > > > > > selection  
> > > > > > squeezing state and context into the URL.
> > > > 
> > > > Does this way lie madness/dragons?  
> > > > [snip]
