auto_complete with multiple params

I'm using the auto_complete plugin, and it works great, my problem is i need to pass multiple parameters to the controller other that what is typed in the text field.

<%= text_field_with_auto_complete :search, :contains, :size => 15, :frequency => 0.1, :skip_style => true -%>

This is what i have as of now, but i also need to pass ":language => @default" because two words can have the same spelling in multiple languages and I don't want to confuse the user.

If you know how to pass multiple parameters to the controller using text_field_with_auto_complete, then please let me know. Thanks!

The hash with autocompletion options accepts a standard Ajax :with parameter. For example, you could send an entire form containing the text field this way:

:skip_style => true, :with => "$('my-superb-form').serialize()"

Xavier Noria wrote:

If you know how to pass multiple parameters to the controller using text_field_with_auto_complete, then please let me know. Thanks!

The hash with autocompletion options accepts a standard Ajax :with parameter. For example, you could send an entire form containing the text field this way:

:skip_style => true, :with => "$('my-superb-form').serialize()"

Right now i have

<% form_for :search, @search, :url => { :action => "search"}, :html => {:id => 'my-superb-form', :name => 'my-superb-form'} do |f| %>

<%= f.text_field( :nonsense, :value => "double checking") %>

<%= select_tag :language, options_for_select(["English", "French", "Spanish"]) %>

<%= text_field_with_auto_complete :search, :contains, :size => 15,         :frequency => 0.1, :skip_style => true,         :with => "$('my-superb-form').serialize()" -%>

<% f.submit 'Search' %>

<% end %>

when i check my log all i see is

Parameters: {"search"=>{"contains"=>"a"}, "authenticity_token"=>"bb42c98bf1b8a9497e1f08b5de88cf06c49dd38c", "controller"=>"phrases", "action"=>"auto_complete_for_search_contains"}

I also tried using :with => "'arbitrary_value='+English" -%>

and get the same result, I am using rails 2.0.2 on mac osx 10.5. Thanks for your help so far!!

The signature of the helper is:

text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})

so you need to separate the option hashes because otherwise everything builds just tag_options:

<%# untested, note curlies around :size %> <%= text_field_with_auto_complete :search, :contains, {:size => 15},        :frequency => 0.1, :skip_style => true,        :with => "$('my-superb-form').serialize()" -%>

check out this thread:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/f17fe9d54c45fa11/ee6938c17684dc20?hl=en&lnk=st&q=auto_complete#ee6938c17684dc20

You can use the :url option. The symbols you set after :action will be appended to the querystring.

<%= text_field_with_auto_complete :my_field, "Enter some text", {:url =>{:action => 'auto_complete_action_name', :my_param => "hello"}, :method => :get} %>

best. mike

Michael Breen wrote:

check out this thread:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/f17fe9d54c45fa11/ee6938c17684dc20?hl=en&lnk=st&q=auto_complete#ee6938c17684dc20

You can use the :url option. The symbols you set after :action will be appended to the querystring.

<%= text_field_with_auto_complete :my_field, "Enter some text", {:url =>{:action => 'auto_complete_action_name', :my_param => "hello"}, :method => :get} %>

best. mike

this didn't work

<%= text_field_with_auto_complete :search, :contains,                {:url => {:action => "auto_complete_for_search_contains",                 :language => "English" }, :method => :get} %>

produced the code

  Parameters: {"search"=>{"contains"=>"a"}, "authenticity_token"=>"2c9f26a81557318a3d7ce1ff64bc57bea43c5fdc", "controller"=>"phrases", "action"=>"auto_complete_for_search_contains"}

i tried pretty much every combination of :url :html and curley braces that is humanly possible and nothing seemed to work, any suggestions?

Rails 2.0.2 running script/plugin install http://svn.rubyonrails.org/rails/plugins/auto_complete

Just out of curiosity, how is the route defined?

best. mike

This is how I have my autocomplete action defined:

map.resources :the_controller, :collection =>
{:auto_complete_action_name => :get}

Michael Breen wrote:

This is how I have my autocomplete action defined:

map.resources :the_controller, :collection => {:auto_complete_action_name => :get}

thats not defined for me in my routes.rb, or in my vendors folder where did you find that?

You need to manually define it in your routes.rb:

ActionController::Routing::Routes.draw do |map|   map.resources :phrases, :collection =>
{:auto_complete_for_search_contains => :get }   map.connect ':controller/:action.'   map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format' end

have you seen this tutorial Trix - Ruby & Javascript Experts

best. mike

Thanks a bunch, i didn't even see your earlier post about the tag options, that was the key, just had to put everything inside of {}.

<%= text_field_with_auto_complete :search, :contains, {:size => 15, :frequency => 0.1, :skip_style => true},{:url => {:action => "auto_complete_for_search_contains", :language => @default}} -%>

works like a charm, thanks for sticking with me!!