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!

On Fri, Jun 13, 2008 at 1:33 AM, Richard S.
[email protected] 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()”

Xavier N. wrote:

On Fri, Jun 13, 2008 at 1:33 AM, Richard S.
[email protected] 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!!

On Sat, Jun 14, 2008 at 4:28 AM, Richard S.
[email protected] wrote:

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

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 B. 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 B. 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?

Michael B. wrote:

Just out of curiosity, how is the route defined?

best.
mike

ActionController::Routing::Routes.draw do |map|
map.resources :phrases
map.connect ‘:controller/:action.’
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end

Not exactly sure if i under stand what you’re looking for so let me know
if this isn’t it.

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
http://trix.pl/blog/auto-complete-for-rails-2-0-tutorial.html

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!!