Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Renamed remote_sortable to sortable_element

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1526 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b17e17898133812abf1f9405cdc6db0ee3879a52 1 parent 521d5fd
@dhh dhh authored
View
31 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
View
3  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) }
Please sign in to comment.
Something went wrong with that request. Please try again.