# Avoiding Clutter in views

**URL:** <https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551>\
**Category:** Rails\
**Created:** [December 13, 2008, 10:46am UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551 "2008-12-13T10:46:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rishav\_Rastogi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@Rishav\_Rastogi](https://www.ruby-forum.com/u/Rishav_Rastogi)\
**Post date:** [December 13, 2008, 10:46am UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551/1 "2008-12-13T10:46:18Z")

</div>

Hi,

I have seen that when using rails for big applications especially the  
ones  
with a lot of dynamic content. for example: profile pages in social  
network  
apps, newspaper websites etc.

The Views in such rails apps seem to have a lot of clutter, lots of  
render  
statements, ‘if’ statements etc.etc. Is there a way to avoid it or  
cleaner  
way to do it.

Thanks,  
Rishav

---

<div class="post-metadata">

**Author:** ![Rishav\_Rastogi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@Rishav\_Rastogi](https://www.ruby-forum.com/u/Rishav_Rastogi)\
**Post date:** [December 13, 2008, 10:52am UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551/2 "2008-12-13T10:52:47Z")

</div>

Hi Rishav,

The cleanest way is to try and move as much logic into the models and  
controllers( depending on the context) and then moving a lot of the  
repetitive view logic into partials.

There is an excellent video on this on RailsCasts

> **[\#55 Cleaning Up the View - RailsCasts](http://railscasts.com/episodes/55-cleaning-up-the-view)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Hope this helps.

Rob

---

<div class="post-metadata">

**Author:** ![Rishav\_Rastogi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@Rishav\_Rastogi](https://www.ruby-forum.com/u/Rishav_Rastogi)\
**Post date:** [December 14, 2008, 9:15am UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551/3 "2008-12-14T09:15:06Z")

</div>

Don’t forget about helpers. Helpers that take blocks are especially  
useful, it’s a really easy way to conditionally display some content  
without cluttering the view.

# Helper

def is\_authorized(action, resource, &block)  
yield if current\_user.permission\_check(action, resource)  
end

# View

\<% is\_authorized(:edit, @user) do %\>  
\<%= link\_to “Edit”, edit\_user\_path(@user) %\>  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![Rishav\_Rastogi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@Rishav\_Rastogi](https://www.ruby-forum.com/u/Rishav_Rastogi)\
**Post date:** [December 14, 2008, 11:10am UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551/4 "2008-12-14T11:10:54Z")

</div>

What are the performance impacts of these various techniques?

Has anyone managed or reduced complexity using layouts in any  
particularly  
clever ways?

al

---

<div class="post-metadata">

**Author:** ![Rishav\_Rastogi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@Rishav\_Rastogi](https://www.ruby-forum.com/u/Rishav_Rastogi)\
**Post date:** [December 16, 2008, 3:09pm UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551/5 "2008-12-16T15:09:20Z")

</div>

Hi guys,

Thanks for the replies. I have tried a bunch of the things mentioned  
above but still even with the partials and moving code to the  
helpers,I dont like the result.  
May be I haven’t done things right. But humor me for a thought I had  
when thinking about the solution…  
I have simple profile page filled up with content from different  
models and the page is full of “render” statements. Is there a more  
CMS type solution here.

Like for example in Drupal,(aside from the fact its a little  
inflexible) , manages views in a very clean and decoupled manner  
from the actual application. It delegates the page content to php  
variables Like “side-bar” “content” “footer” which acts like a base  
theme and then you can have separate sub themes managing individual  
components. The sub themes are combined and put in place in the base  
theme to render the final output without (atleast most of the time)  
the user telling Drupal.

Can anyone recommend any good Rails / Ruby based CMS?

Thanks  
Rishav

---

<div class="post-metadata">

**Author:** ![Rishav\_Rastogi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@Rishav\_Rastogi](https://www.ruby-forum.com/u/Rishav_Rastogi)\
**Post date:** [December 18, 2008, 1:24pm UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551/6 "2008-12-18T13:24:02Z")

</div>

Rishav,

You should check out Radiant CMS. It’s Rails-based and has the same  
type of content parts to the pages that you’re describing from Drupal.

~Thadd

---

<div class="post-metadata">

**Author:** ![Rishav\_Rastogi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ce73a5/32.png) [@Rishav\_Rastogi](https://www.ruby-forum.com/u/Rishav_Rastogi)\
**Post date:** [December 20, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/avoiding-clutter-in-views/155551/7 "2008-12-20T12:03:10Z")

</div>

I’ll check it out

Thanks  
Rishav
