# Uneasy conditionals in views?

**URL:** <https://www.ruby-forum.com/t/uneasy-conditionals-in-views/129981>\
**Category:** Rails\
**Created:** [February 23, 2008, 4:09pm UTC](https://www.ruby-forum.com/t/uneasy-conditionals-in-views/129981 "2008-02-23T16:09:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cujigar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@cujigar](https://www.ruby-forum.com/u/cujigar)\
**Post date:** [February 23, 2008, 4:09pm UTC](https://www.ruby-forum.com/t/uneasy-conditionals-in-views/129981/1 "2008-02-23T16:09:53Z")

</div>

I have many such conditionals in my views:  
…

- ...
\> ...

I am specifically referring to the conditionals in the above code. They  
don’t look very bad. But still, Something is definitely off, this can  
look better. But how?

would love to hear some comments, how do you guys handle such cases in  
code?

thanks.  
RoR rocks!!!

---

<div class="post-metadata">

**Author:** ![cujigar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@cujigar](https://www.ruby-forum.com/u/cujigar)\
**Post date:** [February 23, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/uneasy-conditionals-in-views/129981/2 "2008-02-23T18:05:07Z")

</div>

Jigar G. wrote:

> I have many such conditionals in my views:  
> …
> 
> -

The ones that control business logic should refactor into the models,  
and the  
ones that control view logic (such as a style= tag) should refactor into  
helpers.

Next, for larger extents of non-DRY RHTML code, use partials.

> \>
> 
> Going in the other direction, feel free to put the \<%=%\> _inside_ the  
> style=’’.  
> Then it’s safely empty if it’s nothing.
> 
> Also always follow a perfect “symetry” rule. You don’t break it here,  
> but  
> abusing partials and \<%=%\> might lead to that. Always have the \< in the  
> same  
> code region as its \>, the same for " and " on both sides of an attribute  
> value,  
> and balanced tags like
> 
> and 
> . Don’t move one of those in a  
> partial or  
> something if you can help it!
> 
> And test the snot out of your views with assert\_select and assert\_ypath.  
> The  
> former gives a coarse but complete view of your HTML, and the latter is  
> as  
> precise as advanced XPath statements can get.
> 
> –  
> Phlip

---

<div class="post-metadata">

**Author:** ![cujigar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@cujigar](https://www.ruby-forum.com/u/cujigar)\
**Post date:** [February 23, 2008, 7:54pm UTC](https://www.ruby-forum.com/t/uneasy-conditionals-in-views/129981/3 "2008-02-23T19:54:18Z")

</div>

> And test the snot out of your views with assert\_select and assert\_ypath.

Uh, assert\_xpath?

assert\_ypath’s time is not yet come! (-:
