Forum: Ruby on Rails Avoiding Clutter in views

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9cfa271fb69f3c757657d10aa29fc65b?d=identicon&s=25 Rishav Rastogi (Guest)
on 2008-12-13 10:46
(Received via mailing list)

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

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

Dfe81d0ef18761dc22d0586b7b58c5ac?d=identicon&s=25 Robert Zolkos (Guest)
on 2008-12-13 10:52
(Received via mailing list)
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

Hope this helps.

6fabb84e727dee98d1277df56458cbac?d=identicon&s=25 Andrew Bloom (Guest)
on 2008-12-14 09:15
(Received via mailing list)
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)

# View
<% is_authorized(:edit, @user) do %>
  <%= link_to "Edit", edit_user_path(@user) %>
<% end %>
1128ccdc6b414a39e38f00acca680b8d?d=identicon&s=25 Alan Brown (Guest)
on 2008-12-14 11:10
(Received via mailing list)
What are the performance impacts of these various techniques?

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

9cfa271fb69f3c757657d10aa29fc65b?d=identicon&s=25 rishav (Guest)
on 2008-12-16 15:09
(Received via mailing list)
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?

D59ea0bcdbdea2c3b9bd0dfbd928296b?d=identicon&s=25 Thadd (Guest)
on 2008-12-18 13:24
(Received via mailing list)

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.

9cfa271fb69f3c757657d10aa29fc65b?d=identicon&s=25 rishav (Guest)
on 2008-12-20 12:03
(Received via mailing list)
I'll check it out

This topic is locked and can not be replied to.