Zoran Kikic
2007-Oct-08 17:06 UTC
how to pass 2 variables to controller from <a href="#" onCli
I want to pass 2 variables (@variableA, @variableB) to my controller "search" when the following href is clicked: myView.rhtml: <li><a href="#" onclick="Element.show(''spinner''); new Ajax.Updater(''resultsTable'', ''/search'',{ asynchronous:true, evalScripts:true, onSuccess:function(request){ Element.hide(''spinner'') } });return false;"> <b>HOTEL</b></a> </li> I need the 2 variables for my condition string, which should work something like this: conditions = ["hotel_id = ? AND city_id = ?", @variableA, @variableB] unless @hotel_id.nil? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Oct-08 17:11 UTC
Re: how to pass 2 variables to controller from <a href="#" onCli
On 8 Oct 2007, at 18:06, Zoran Kikic wrote: link_to_remote ''Hotel'', :url => {:action => ''search'', :a => ''123'', :b => ''456''}, :before => "Element.show(''spinner'')", :success=> "Element.hide(''spinner'')"> > I want to pass 2 variables (@variableA, @variableB) to my controller > "search" when the following href is clicked: > > myView.rhtml: > <li><a href="#" onclick="Element.show(''spinner''); > new Ajax.Updater(''resultsTable'', > ''/search'',{ > asynchronous:true, > evalScripts:true, > onSuccess:function(request){ > Element.hide(''spinner'') > } > });return false;"> > <b>HOTEL</b></a> > </li> > > I need the 2 variables for my condition string, which should work > something like this: > > conditions = ["hotel_id = ? AND city_id = ?", @variableA, @variableB] > unless @hotel_id.nil? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shandy Nantz
2007-Oct-08 17:16 UTC
Re: how to pass 2 variables to controller from <a href="#" onCli
Zoran Kikic wrote:> myView.rhtml: > <li><a href="#" onclick="Element.show(''spinner''); > new Ajax.Updater(''resultsTable'', > ''/search'',{ > asynchronous:true, > evalScripts:true, > onSuccess:function(request){ > Element.hide(''spinner'') > } > });return false;"> > <b>HOTEL</b></a> > </li>Are you hard coding the link like that? Because you are using a help you could say: <%= link_to ''Home'', { :action => ''home_form'', :id => ''arg_1'', :id2 => ''arg_2'' } %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Zoran Kikic
2007-Oct-08 17:32 UTC
Re: how to pass 2 variables to controller from <a href="#" o
> Are you hard coding the link like that? Because you are using a help you > could say: > > <%= link_to ''Home'', { :action => ''home_form'', :id => ''arg_1'', :id2 => > ''arg_2'' } %>yes, it''s hard coded because of my quite extensive stylesheet (a, b, ul, li..) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Zoran Kikic
2007-Oct-08 18:41 UTC
Re: how to pass 2 variables to controller from <a href="#" o
Thank you guys, this looks ugly but it works now: <a href="#" onclick="Element.show(''spinner''); new Ajax.Updater(''resultsTable'',''/search?arg1=1&arg2=2'',{ asynchronous:true, evalScripts:true, onSuccess:function(request){ Element.hide(''spinner'') }});return false;"><b>HOTEL</b></a> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Zoran Kikic
2007-Oct-08 20:17 UTC
Re: how to pass 2 variables to controller from <a href="#" o
a better solution: <%= link_to_remote "<b>HOME</b>", { :url => { :controller => "search", :action => "index", :arg1 => "1", :arg2 => "2" }, :update => "resultsTable", :success => "Element.hide(''spinner'')" } %></li> link_to_remote "<b>HOME</b>" is certainly not perfect, but I can live with this :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Zoran, Since you''re hard-coding all of this, an even better solution would be to use a named route. You add named routes in the config/routes.rb file. Search for ''named route'' and it''ll give you an example (around line 10 of a vanilla routes.rb). In your case you''d probably add something like this: map.connect ''home'', :controller=>''search'', :action=>''index'', :arg1=>1, :arg2=> Then your method call is reduced to: link_to_remote "<b>Home</ b>", :url=>home_url, :update=>''resultsTable'', :sucess=>''Element.hide(''spinner'') As an observation, you might want to also change :success to :complete. That way the spinner gets hidden even with an error response (success only triggers with a 200 response). On Oct 8, 4:17 pm, Zoran Kikic <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> a better solution: > > <%= link_to_remote "<b>HOME</b>", { :url => { :controller => "search", > :action => "index", :arg1 => "1", :arg2 => "2" }, :update => > "resultsTable", :success => "Element.hide(''spinner'')" } %></li> > > link_to_remote "<b>HOME</b>" is certainly not perfect, but I can live > with this :) > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---