# Link\_to question

**URL:** <https://www.ruby-forum.com/t/link-to-question/50149>\
**Category:** Rails\
**Created:** [December 13, 2005, 5:14pm UTC](https://www.ruby-forum.com/t/link-to-question/50149 "2005-12-13T17:14:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [December 13, 2005, 5:14pm UTC](https://www.ruby-forum.com/t/link-to-question/50149/1 "2005-12-13T17:14:44Z")

</div>

I’m confused at the following problem: I’m trying to use a link\_to to  
call a controller/view from itself. Basically, history\_console.rhtml  
calls its controller in the link\_to, and based on the value of the  
select\_id it will display different things.

But with the following code, history\_console.rhtml will get a select\_id,  
but not a specific value of 1 (so if in the controller I say @select\_id  
= 1 it works). So it cannot differentiate what to display.

This code is in history\_console.rhtml:

\<%= link\_to ‘Client’, :action =\> ‘history\_console’, :select\_id =\> 1 %\>

This is in the relevant controller:  
def history\_console  
if(params[:select\_id])  
@select\_id = (params[:select\_id])  
@clients = Client.find(:all)  
end  
end

And this is (again) in history\_consle.rhtml  
\<% if @select\_id == 1 %\>  
\<%= render\_partial ‘clientselect’ %\>  
\<% end %\>

And the URL appears with history\_console?select\_id=1

The problem is that the value of select\_id in the controller is not 1,  
and I don’t know why or what it really is.

What am I missing? How do I handle variables in this fashion?

Thanks!

Nathan M.

Operations Director

Northeast Region

Pilgrim IT, LLC

NORTHEAST OFFICE

1 Short Street

Northampton, MA 01060

TEL 866.434.4976

FAX 413.587.0572

MIDWEST OFFICE

1815 Brownsboro Road

Louisville, KY 40206

TEL 502.721.7939

FAX 502.721.7940

NOTICE: This email and any attachments are intended only for the  
addressee and may contain information that is confidential and/or  
legally privileged. If you are not the intended recipient or have  
received this email in error, please notify the sender by return email  
or by calling 866-434-4976. You should then delete the message and any  
attachments or copies. If you are not the intended recipient, you are  
prohibited from retaining, distributing, disclosing or using any  
information contained herein.

---

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [December 13, 2005, 5:43pm UTC](https://www.ruby-forum.com/t/link-to-question/50149/2 "2005-12-13T17:43:16Z")

</div>

Your select\_id is probably being passed as a string and you are  
comparing it to an integer. That is probably causing your test to fail.  
Try changing all the 1’s to “1”'s and test it again.

---

<div class="post-metadata">

**Author:** ![nmotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nmotter](https://www.ruby-forum.com/u/nmotter)\
**Post date:** [December 13, 2005, 8:37pm UTC](https://www.ruby-forum.com/t/link-to-question/50149/3 "2005-12-13T20:37:00Z")

</div>

I ran into a similar problem yesterday. This happens when you have form  
fields coming in as strings, and you want to compare them as integers as  
well.

In this case I went with something like this:

if params[:some\_field].to\_i == 2 then  
…  
end

You might want to try that as well.
