Sha256: 1ab221e041bcdbcb8ef5fb38d07b6e3c4e2751b4133f59b883f2f3a51aed4ab2
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 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? #allow specifying fully qualified class name for model object class_name = options[:class_name] || object items = get_autocomplete_items(:model => get_object(class_name), \ :options => options, :term => term, :method => method) else items = {} end render :json => json_for_autocomplete(items, options[:display_value] ||= method, options[:extra_data]) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails3-jquery-autocomplete-0.6.3 | lib/rails3-jquery-autocomplete/autocomplete.rb |