# Using if statements in View

**URL:** <https://www.ruby-forum.com/t/using-if-statements-in-view/142638>\
**Category:** Rails\
**Created:** [July 9, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/using-if-statements-in-view/142638 "2008-07-09T23:57:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![recent\_convert\_S\_me](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@recent\_convert\_S\_me](https://www.ruby-forum.com/u/recent_convert_S_me)\
**Post date:** [July 9, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/using-if-statements-in-view/142638/1 "2008-07-09T23:57:53Z")

</div>

Hi out there. I am trying to create a table that displays  
information, and then changes the class of the row if a flag is  
presented, but can’t determine if putting it in the view is the best  
method for doing so or not. Right now, I have tried this in my view,  
but it currently sets the columns to whichever is set into the if  
statements first.

\<% for widget in @widgets %\>  
\<% if widget.flag = “–” && widget.second\_flag = “–”%\>

  
\<% elsif widget.flag = “++” || widget.second\_flag = “++”%\>  
  
\<% elsif widget.flag = “–” || widget.second\_flag = “–”%\>  
  
\<%else%\>  
\<tr class=“d\<%= cycle(“0”, “1”) %\>”\>  
\<%end%\>

If anyone has any advice, I would be very appreciative.

---

<div class="post-metadata">

**Author:** ![recent\_convert\_S\_me](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@recent\_convert\_S\_me](https://www.ruby-forum.com/u/recent_convert_S_me)\
**Post date:** [July 10, 2008, 12:00am UTC](https://www.ruby-forum.com/t/using-if-statements-in-view/142638/2 "2008-07-10T00:00:49Z")

</div>

On Jul 9, 10:50 pm, “recent convert = me” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi out there. I am trying to create a table that displays  
> information, and then changes the class of the row if a flag is  
> presented, but can’t determine if putting it in the view is the best  
> method for doing so or not. Right now, I have tried this in my view,  
> but it currently sets the columns to whichever is set into the if  
> statements first.
> 
> \<% for widget in @widgets %\>  
> \<% if widget.flag = “–” && widget.second\_flag = “–”%\>

Check your ruby: = is the assignment operator, == is the comparison  
operator. You’d probably find this all flowed more naturally if you  
wrapped this up in a view helper.

Fred
