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:

  • 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?

    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’)”

    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’ } %>

    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…)

    Thank you guys,

    this looks ugly but it works now:

    HOTEL

    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 :slight_smile:

    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]