# Problem with local variable in partial template

**URL:** <https://www.ruby-forum.com/t/problem-with-local-variable-in-partial-template/86430>\
**Category:** Rails\
**Created:** [February 22, 2007, 6:58am UTC](https://www.ruby-forum.com/t/problem-with-local-variable-in-partial-template/86430 "2007-02-22T06:58:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 22, 2007, 6:58am UTC](https://www.ruby-forum.com/t/problem-with-local-variable-in-partial-template/86430/1 "2007-02-22T06:58:37Z")

</div>

I am quite new at Ruby and Rails and this is stumping me:

I have in my rhtml file:

\<%= render(:partial =\> "owner", :collection =\> @business.owners, :locals =\> { :that\_value=\> @params[:that\_value] } ) %\>

then in my partial:

\<% if owner.id == that\_value %\>

- \<%= owner.name %\> \<%= owner.id %\> \<%= that\_value%\> 
\<% else %\> - \<%= owner.name %\> \<%= owner.id %\> 
\<% end %\> \<%= owner.id == that\_value%\> \<%=owner.id%\> \<%=that\_value%\>

owner.id == that\_value evaluates to false every time, even when they  
are really the same.

Sample output:

Owner Number1 1  
False  
1 2  
Owner Number2 2  
False  
2 2  
Owner Number3 3  
False  
3 2

I am an old C guy and I keep thinking that there must be some typing  
error, like one of the “2” is a string and the other is an int, but I  
thought ruby has no types. I am pretty stumped, hopefully someone can  
help.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 22, 2007, 3:35pm UTC](https://www.ruby-forum.com/t/problem-with-local-variable-in-partial-template/86430/2 "2007-02-22T15:35:42Z")

</div>

And if I change \<% if owner.id == that\_value %\> to \<% if owner.id \<\>  
that\_value %\> it fails.

On Feb 21, 11:57 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 22, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/problem-with-local-variable-in-partial-template/86430/3 "2007-02-22T15:41:43Z")

</div>

It’s really confusing because they both print out as being the same  
(in this case 2) but they don’t compare to be equal with each other…

On Feb 22, 8:34 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 22, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/problem-with-local-variable-in-partial-template/86430/4 "2007-02-22T22:44:27Z")

</div>

removed\_email\_address@domain.invalid wrote:

> It’s really confusing because they both print out as being the same  
> (in this case 2) but they don’t compare to be equal with each other…
> 
> On Feb 22, 8:34 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Your most likely comparing a string to an integer

1 == “1” #=\> false

All params come in as strings. If you want it to be treated as an  
integer, you can convert it easily.

1 == “1”.to\_i #=\> true

So in your locals hash you can do:

:locals =\> {:that\_value =\> params[:that\_value].to\_i}
