Forum: Ruby on Rails link_to question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0b8601544389bf0603f63bfe5afae865?d=identicon&s=25 Nathan Mealey (Guest)
on 2005-12-13 17:14
(Received via mailing list)
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
  @select_id = (params[:select_id])
  @clients = Client.find(:all)

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?


Nathan Mealey

Operations Director

Northeast Region

Pilgrim IT, LLC


1 Short Street

Northampton, MA 01060

TEL  866.434.4976

FAX  413.587.0572


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.
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (Guest)
on 2005-12-13 17:43
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.
Efe398b3b5436b0a8d4430090e8f86ea?d=identicon&s=25 subimage interactive (Guest)
on 2005-12-13 20:37
(Received via mailing list)
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

In this case I went with something like this:

if params[:some_field].to_i == 2 then

You might want to try that as well.
This topic is locked and can not be replied to.