# MVC Philosophy

**URL:** <https://www.ruby-forum.com/t/mvc-philosophy/92506>\
**Category:** Rails\
**Created:** [April 20, 2007, 3:08am UTC](https://www.ruby-forum.com/t/mvc-philosophy/92506 "2007-04-20T03:08:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [April 20, 2007, 3:08am UTC](https://www.ruby-forum.com/t/mvc-philosophy/92506/1 "2007-04-20T03:08:44Z")

</div>

My directory browsing app shows lists of file. If the item is a folder,  
show a folder icon and link to the action that shows directory contents.  
If the item is a graphics file, show a thumbnail and link to a larger  
view. If the item is a non-graphics file, show an appropriate icon and  
stream the file if the link is clicked.

The controller creates an array of arrays of items in the current  
folder, with flags indicating the type of the item. The view iterates  
over the array to create the page.

But the view code looks a lot like programming code, with if-then and  
case statements to handle all the possibilities. It _feels_ like it  
belongs in the controller. I could remove some code into partials and  
helpers, but that’s really just distributing the ugliness around.

On the other hand, using a controller to build an array of html links  
doesn’t seem right either.

Philosophically, which way should I go?

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [April 20, 2007, 3:33am UTC](https://www.ruby-forum.com/t/mvc-philosophy/92506/2 "2007-04-20T03:33:24Z")

</div>

Brian A. wrote:

> But the view code looks a lot like programming code, with if-then and  
> case statements to handle all the possibilities. It _feels_ like it  
> belongs in the controller. I could remove some code into partials and  
> helpers, but that’s really just distributing the ugliness around.
> 
> On the other hand, using a controller to build an array of html links  
> doesn’t seem right either.
> 
> Philosophically, which way should I go?

Hmm… Personally, I think the controller should mark it as folder,  
graphic or other and the view should have a case statement to pick up  
the partial that should be used for rendering the view for it. The  
partial might want to use a helper for things like thumbnails, etc. if  
required…

Just my thoughts! 🙂  
Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [April 20, 2007, 4:32am UTC](https://www.ruby-forum.com/t/mvc-philosophy/92506/3 "2007-04-20T04:32:35Z")

</div>

Brian A. wrote:

> My directory browsing app shows lists of file. If the item is a folder,  
> show a folder icon and link to the action that shows directory contents.  
> If the item is a graphics file, show a thumbnail and link to a larger  
> view. If the item is a non-graphics file, show an appropriate icon and  
> stream the file if the link is clicked.
> 
> The controller creates an array of arrays of items in the current  
> folder, with flags indicating the type of the item. The view iterates  
> over the array to create the page.
> 
> But the view code looks a lot like programming code, with if-then and  
> case statements to handle all the possibilities. It _feels_ like it  
> belongs in the controller. I could remove some code into partials and  
> helpers, but that’s really just distributing the ugliness around.
> 
> On the other hand, using a controller to build an array of html links  
> doesn’t seem right either.
> 
> Philosophically, which way should I go?

It is hard to give advise without seeing your code. I think using  
helpers and/or partials is the way to go. Hmmm… having flags seems  
like a bad code smell. Each item should have its own type and with that  
being the case you can do stuff like this:

\<%= render :partial =\> “#{item.class.to\_s.downcase}\_show\_link” %\>

Hope this helps.
