narozk
October 8, 2007, 7:06pm
#1
I want to pass 2 variables (@variableA , @variableB ) to my controller
“search” when the following href is clicked:
myView.rhtml:
HOTEL
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 ?
narozk
October 8, 2007, 7:12pm
#2
On 8 Oct 2007, at 18:06, Zoran K. wrote:
link_to_remote ‘Hotel’, :url => {:action => ‘search’, :a =>
‘123’, :b => ‘456’},
:before => “Element.show(‘spinner’)”,
:success=> “Element.hide(‘spinner’)”
narozk
October 8, 2007, 7:16pm
#3
Zoran K. wrote:
myView.rhtml:
HOTEL
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’ } %>
narozk
October 8, 2007, 7:32pm
#4
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…)
narozk
October 8, 2007, 8:41pm
#5
Thank you guys,
this looks ugly but it works now:
HOTEL
narozk
October 8, 2007, 10:17pm
#6
a better solution:
<%= link_to_remote “HOME ”, { :url => { :controller => “search”,
:action => “index”, :arg1 => “1”, :arg2 => “2” }, :update =>
“resultsTable”, :success => “Element.hide(‘spinner’)” } %>
link_to_remote “HOME ” is certainly not perfect, but I can live
with this
narozk
October 10, 2007, 7:15pm
#7
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 “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 K. [email protected]