# Comparing 2 variable

**URL:** <https://www.ruby-forum.com/t/comparing-2-variable/104555>\
**Category:** Rails\
**Created:** [May 19, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/comparing-2-variable/104555 "2007-05-19T14:25:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhaval](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@dhaval](https://www.ruby-forum.com/u/dhaval)\
**Post date:** [May 19, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/comparing-2-variable/104555/1 "2007-05-19T14:25:02Z")

</div>

hello

I want to compare 2 variables the variables gets the data from the  
database

\<% for subnew in @subnews %\>

\<% if( @news\_id == subnew[“news\_id”]) %\>  
.  
.  
.  
.  
.  
action  
.  
.  
.  
.  
end

the news\_id is getting the value from the controller but when comparing  
in rails they want \<%= news\_id == subnew[“news\_id”]) %\> where as i want  
to make it in @news\_id but its not working

please suggest me some new method for it

thanks

---

<div class="post-metadata">

**Author:** ![dhaval](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@dhaval](https://www.ruby-forum.com/u/dhaval)\
**Post date:** [May 19, 2007, 3:20pm UTC](https://www.ruby-forum.com/t/comparing-2-variable/104555/2 "2007-05-19T15:20:25Z")

</div>

try \<% if( @news.id.to\_s == subnew[“news\_id”].to\_s) %\>

dhaval wrote:

> hello
> 
> I want to compare 2 variables the variables gets the data from the  
> database

> the news\_id is getting the value from the controller but when comparing  
> in rails they want \<%= news\_id == subnew[“news\_id”]) %\> where as i want  
> to make it in @news\_id but its not working
> 
> please suggest me some new method for it
> 
> thanks

---

<div class="post-metadata">

**Author:** ![dhaval](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@dhaval](https://www.ruby-forum.com/u/dhaval)\
**Post date:** [May 21, 2007, 7:27am UTC](https://www.ruby-forum.com/t/comparing-2-variable/104555/3 "2007-05-21T07:27:21Z")

</div>

thanks a lot it worked
