# How much view logic should be displayed in views?

**URL:** <https://www.ruby-forum.com/t/how-much-view-logic-should-be-displayed-in-views/128774>\
**Category:** Rails\
**Created:** [February 11, 2008, 1:40pm UTC](https://www.ruby-forum.com/t/how-much-view-logic-should-be-displayed-in-views/128774 "2008-02-11T13:40:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobycatlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tobycatlin](https://www.ruby-forum.com/u/tobycatlin)\
**Post date:** [February 11, 2008, 1:40pm UTC](https://www.ruby-forum.com/t/how-much-view-logic-should-be-displayed-in-views/128774/1 "2008-02-11T13:40:54Z")

</div>

Hi,

I have a few cases where a particular value on a page should take 1 of  
2 values and so at the top of the template I chose which:

\<%  
count = @count1 || @count2  
%\>  
\<%= count %\>

Often the decision between the two is a little more complicated e.g.,  
based on their values. The question is where should this sort of code  
go? In a helper? It is the controller that generates the instance  
variables @count1 and @count2 so it could very easily do the whole  
calculation and create another instance variable (both @count1 and  
@count2 are used elsewhere in the page so are still required). Or  
should this sort of thing be an attribute on a model?

I am never sure where this sort of logic should go as it is kind of  
view logic and kind of business logic.

Thanks in advance,  
Toby

---

<div class="post-metadata">

**Author:** ![tobycatlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tobycatlin](https://www.ruby-forum.com/u/tobycatlin)\
**Post date:** [February 11, 2008, 1:50pm UTC](https://www.ruby-forum.com/t/how-much-view-logic-should-be-displayed-in-views/128774/2 "2008-02-11T13:50:19Z")

</div>

You’re right, that kind of logic is difficult to place. I have seen  
one clean solution to this, though: Presenters

> **[The Exceptional Presenter](https://spin.atomicobject.com/2008/01/27/the-exceptional-presenter/)**
>
> PresentationObject is an implementation of Jay Fields’ Presenter pattern in Rails. It has familiar declarative style syntax and offers encapsulating presentation logic in a testable object.

Jason
