diff --git a/actionpack/lib/action_controller/auto_complete.rb b/actionpack/lib/action_controller/auto_complete.rb new file mode 100644 index 0000000000000000000000000000000000000000..606f43b350ff041ce52b6fa492de84c684f28274 --- /dev/null +++ b/actionpack/lib/action_controller/auto_complete.rb @@ -0,0 +1,31 @@ +module ActionController + # Example: + # + # # Controller + # class BlogController < ApplicationController + # auto_complete_for :post, :title + # end + # + # # View + # <%= text_field_with_auto_complete :post, title %> + module AutoComplete + def self.append_features(base) #:nodoc: + super + base.extend(ClassMethods) + end + + module ClassMethods + def auto_complete_for(object, method) + define_method("auto_complete_for_#{object}_#{method}") do + @items = object.to_s.camelize.constantize.find( + :all, + :conditions => [ "LOWER(#{method}) LIKE ?", '%' + request.raw_post.downcase + '%' ], + :order => "#{method} ASC" + ) + + render :inline => "<%= auto_complete_result @items, '#{method}' %>" + end + end + end + end +end \ No newline at end of file diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 7b857f4f18a6806c1193189d355b10664eefe166..a53b284c22371a5e4204ae327207a0a2c7e12ec8 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -294,8 +294,7 @@ def visual_effect(name, element_id, js_options = {}) # # You can change the behaviour with various options, see # http://script.aculo.us for more documentation. - # - def remote_sortable(element_id, options = {}) + def sortable_element(element_id, options = {}) options[:with] ||= "Sortable.serialize('#{element_id}')" options[:onUpdate] ||= "function(){" + remote_function(options) + "}" options.delete_if { |key, value| AJAX_OPTIONS.include?(key) }