Forum: Ruby on Rails passing parameter from one autocomplete-jquery to another

Posted by Soichi Ishida (soichi)
on 2012-12-06 04:26
Rails 3.1.3

My app has two consecutive rails3-autocomplete-jquery form_tags
https://github.com/crowdint/rails3-jquery-autocomplete

I want to pass a parameter, which depends on the first
autocomplete_field_tag choice, to the second. The second form should
search based on the parameter.

<%= autocomplete_field_tag :departure_id, '',
autocomplete_city_name_plans_path, :size => 75,
              'data-delimiter' => ' ' %>

<%= autocomplete_field_tag :destination_id, '',
autocomplete_destination_name_plans_path,
              :size => 75, 'data-delimiter' => ' ' %>

They are defined in routes.rb

        resources :plans do
            get :autocomplete_city_name, :on => :collection
            get :autocomplete_destination_name, :on => :collection
        end

I tried using jquery

    $('#departure_id').bind('railsAutocomplete.select', function(event,
data){
  departure = data.item.id;
      if(departure == "") departure="0";
      jQuery.get('/plans/update_destination_select/' + departure,
function(data2){
        ...
     });

can pass a value to an action in plans_controller.rb

    def update_destination_select
        departure = City.find_by_id(params[:id]) unless
params[:id].blank?
        @temp_departure_id = departure.id
        ...
    end

But the class variable @temp_departure_id does not work.

Is there anyway to pass a value from the first autocomplete-jquery to
another?

soichi
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.