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.
on 2005-12-13 18:14
on 2005-12-13 18: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.
on 2005-12-13 21:37
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.