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 Mealey 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. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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. -- Posted via http://www.ruby-forum.com/.
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. On 12/13/05, Kevin Olbrich <kevin.olbrich-4+jYJfmkT58@public.gmane.org> wrote:> > 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. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- seth at subimage interactive http://www.subimage.com/sublog/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Man, I was up until 5am coding Hey, does anyone know how to pass extra paramaters in a link_to - I can''t seem to get the syntax right: This does NOT work: <div id="header"> <ul id="primary"> <li> <%= link_to ''General'',{:action => "new_project",:id => @project},{:class => "current"},{:foo => "bar"}%> </ul> </div> But It shows what I am trying to do It seem it should according to RoR API http://api.rubyonrails.com/classes /ActionView/Helpers/UrlHelper.html #M000332
On Dec 17, 2005, at 17:41, Scott Phelps wrote:> Hey, does anyone know how to pass extra paramaters in a link_to - I > can''t seem to get the syntax right: > > This does NOT work: > <%= link_to ''General'',{:action => "new_project",:id => > @project},{:class => "current"},{:foo => "bar"}%>This does: link_to ''General'', {:action => "new_project", :id => @project, :foo => "bar"}, {:class => "current"} The hash given in the second parameter for link_to, options, is used to build the URL to link to. -- Jakob Skjerning - http://mentalized.net
On Dec 17, 2005, at 11:55 AM, Jakob L. Skjerning wrote:> > On Dec 17, 2005, at 17:41, Scott Phelps wrote: >> Hey, does anyone know how to pass extra paramaters in a link_to - >> I can''t seem to get the syntax right: >> >> This does NOT work: >> <%= link_to ''General'',{:action => "new_project",:id => >> @project},{:class => "current"},{:foo => "bar"}%> > > This does: > > link_to ''General'', {:action => "new_project", :id => @project, :foo > => "bar"}, {:class => "current"} > > The hash given in the second parameter for link_to, options, is > used to build the URL to link to.Cool, thanks!