Sha256: 243933d6c63c8534f04cac7ae8678825d4fa35827185c60ed3521c1bd81cb53b
Contents?: true
Size: 1.05 KB
Versions: 4
Compression:
Stored size: 1.05 KB
Contents
module Rails3JQueryAutocomplete # Inspired on DHH's autocomplete plugin # # Usage: # # class ProductsController < Admin::BaseController # autocomplete :brand, :name # end # # This will magically generate an action autocomplete_brand_name, so, # don't forget to add it on your routes file # # resources :products do # get :autocomplete_brand_name, :on => :collection # end # # Now, on your view, all you have to do is have a text field like: # # f.text_field :brand_name, :autocomplete => autocomplete_brand_name_products_path # # module ClassMethods def autocomplete(object, method, options = {}) define_method("autocomplete_#{object}_#{method}") do term = params[:term] if term && !term.empty? items = get_items(:model => get_object(object), \ :options => options, :term => term, :method => method) else items = {} end render :json => json_for_autocomplete(items, options[:display_value] ||= method) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems