# Controller class UserController < ApplicationController autocomplete_for :user, :name end #Customized.... autocomplete_for :user, :name do |items,method| render :text => items.map{|item| "#{item.send(method)} -- #{item.id}"}.join("\n") end # View <%= f.text_field :auto_user_name, :class => 'autocomplete', 'autocomplete_url'=>autocomplete_for_user_name_users_path %> # Routes map.resources :users, :collection => { :autocomplete_for_user_name => :get} #JS #any library you like #(includes examples for jquery jquery.js + jquery.autocomplete.js + jquery.autocomplete.css ) jQuery(function($){//on document ready //autocomplete $('input.autocomplete').each(function(){ var input = $(this); input.autocomplete(input.attr('autocomplete_url')); }); }); #Model(input/output association) class User find_by_autocomplete('name') end class Post autocomplete_for('user','name') # auto_user_name= + auto_user_name end .
Not as thought free as the default version, but gives you a lot more control.
script/plugin install git://github.com/grosser/simple_auto_complete.git
README
Somehow i missed the point. Probably lost in translation 🙂 Anyway … nice blog to visit.
cheers, Overcame.
Is there a way to override the query to use a custom query?
you can pass e.g. :conditions/:limit/:order etc, and if thats not enought you could add a simple hack(please send me too) to use an option like :scope=>Product.valid.sane
Thanks for the quick reply, very useful plugin and thanks for developing it.
I can pass conditions, but is there a way to pass the param (q) to the conditions? It might be useful to be able to override this in the model (I would try to modify it but have no experience writing plugins).
Thanks
you mean like this ?
:conditions=>[“name like ?”, params[:q].to_s+’%’]
Yes, but I get the error:
undefined local variable or method ‘params’
in the controller when I try to do that. Is this in the right spot?
Thanks
hmm that does not work since its called in the class and not when the method is actually called. Maybe just copy-paste the actual method definition and insert the stuff you need.
Is there a way to override the query to use a custom query?
you can give finder options in the options for the controller method, or just define the method yourself, just copy/past whats inside the define_method block
Do you know why I would be getting this java error:
Uncaught TypeError: undefined is not a function ?
I followed the instructions step by step and can’t seem to get it working. I’m working with rails 2.3.5
Thanks for your time.
nope, should work, we also have it in a 2.3.5 project
Yeah I don’t understand. Everything seems to work fine but right blow the views code I get this error. I see it in my console when using a developer tool like firebug.
Thanks for letting me know at least its not a version issue.
Can simple_autocomplete work with just Prototype/Scriptaculous or must it work with JQuery?
Works with any autocomplete library, as long as it supports the same format.
how to do jQuery autocomplete in rails 3 for search text field,pls say in step by step