Definitely take a look at Florian Hanke's representer-plugin at
http://github.com/floere/representer. It gives you the ability to have
'object oriented' views. You put all the logic (conditionals etc.)
inside methods of the view-object. Much much easier to test and it
results in extra clean views.

If you need more info (in case the documentation is not enough), let
me know.

Andi

On Nov 19, 12:28 am, pharrington <xenogene...@gmail.com> wrote:
> On Nov 18, 4:29 pm, ressister <ressis...@gmail.com> wrote:
>
>
>
>
>
> > I am working on a project that uses quite a bit of conditional logic
> > to display information about groups in a list.  The partial that
> > renders the group attributes will display different info based on
> > whether the user is a) logged in, b) the creator of the group c) a
> > member of the group, etc.
>
> > I find myself using a lot of if/else conditions to render things as
> > they should be.  The thing I dislike the most is that I'm writing the
> > same logic in different places.  For instance, if a user is an admin
> > I'm doing:
>
> > <% if current_user.admin? %>
> >     something...
> > <% end %>
>
> > ...and I do that two or three times in the same template.  What are
> > some other strategies.  Can I use respond_to?  How do people make
> > their view code more readable?  If there are any good resources people
> > know about for this, please respond!
>
> > Thanks,
> > -A
>
> For simple cases you could just create a helper like this:
> def admin_only &blk
>    yield if current_user.admin?
> end
>
> <% admin_only do %>
>   some ISH
> <% end %>

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=.


Reply via email to