Skip to content
This repository was archived by the owner on May 2, 2025. It is now read-only.

Hi! I cleaned up your code for you! #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Logs and databases #
######################
*.log

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
8 changes: 4 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Rails auto_complete plugin. It provides the same auto_complete_for method
for your controllers, but eliminates the various view helper methods, as
those are not needed when using jQuery and Unobtrusive JavaScript.

To use this, you need to have jQuery and the autocomplete plugin mentioned
above (as well as appropriate CSS). Then, there are four aspects of setting
To use this, you need to have jQuery and the autocomplete plugin mentioned
above (as well as appropriate CSS). Then, there are four aspects of setting
up an auto-complete field:

1) Create the text field in your view, which is just a regular form text
field as you'd create in a Rails erb view:

<%= post.text_field :title, :autocomplete =>"off" %>

2) Include the appropriate JS files and CSS in your layout or similar:

<%= stylesheet_link_tag 'jquery.ui.autocomplete' %>
Expand Down Expand Up @@ -49,7 +49,7 @@ the find method used to search for the records:
For more information, see:
* jQuery site: http://jquery.com
* Dylan Verheul jquery autocomplete plugin site: http://www.dyve.net/jquery/?autocomplete
* Good article on jQuery and Rails (note this mentions a different jquery autocomplete
* Good article on jQuery and Rails (note this mentions a different jquery autocomplete
plugin, which was originally used in this plugin): http://errtheblog.com/posts/73-the-jskinny-on-jquery
* Original Rails auto_complete plugin: http://github.com/rails/auto_complete

Expand Down
20 changes: 10 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'rake'
require 'rake/rdoctask'
desc 'Generate documentation for auto_complete plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Auto Complete jQuery'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
require 'rake'
require 'rake/rdoctask'

desc 'Generate documentation for auto_complete plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Auto Complete jQuery'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
10 changes: 5 additions & 5 deletions auto_complete_jquery.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Gem::Specification.new do |s|
s.description = "This plugin provides a auto-complete method for your controllers to be used with Dylan Verheul's jquery autocomplete plugin."
s.has_rdoc = true
s.authors = ["Chris Bailey"]
s.files = ["CHANGELOG",
"README",
"Rakefile",
"auto_complete_jquery.gemspec",
"init.rb",
s.files = ["CHANGELOG",
"README",
"Rakefile",
"auto_complete_jquery.gemspec",
"init.rb",
"lib/auto_complete_jquery.rb"]
s.rdoc_options = ["--main", "README"]
s.extra_rdoc_files = ["CHANGELOG", "README"]
Expand Down
20 changes: 10 additions & 10 deletions lib/auto_complete_jquery.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module AutoCompleteJquery
module AutoCompleteJquery

def self.included(base)
base.extend(ClassMethods)
end
Expand All @@ -17,34 +17,34 @@ def self.included(base)
#
# By default, auto_complete_for limits the results to 10 entries,
# and sorts by the given field.
#
#
# auto_complete_for takes a third parameter, an options hash to
# the find method used to search for the records:
#
# auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC'
#
# For help on defining text input fields with autocompletion,
# For help on defining text input fields with autocompletion,
# see ActionView::Helpers::JavaScriptHelper.
#
# For more on jQuery auto-complete, see the docs for the jQuery autocomplete
# For more on jQuery auto-complete, see the docs for the jQuery autocomplete
# plugin used in conjunction with this plugin:
# * http://www.dyve.net/jquery/?autocomplete
module ClassMethods
def auto_complete_for(object, method, options = {})
define_method("auto_complete_for_#{object}_#{method}") do
object_constant = object.to_s.camelize.constantize
find_options = {
:conditions => [ "LOWER(#{method}) LIKE ?", '%' + params[:q].downcase + '%' ],

find_options = {
:conditions => [ "LOWER(#{method}) LIKE ?", '%' + params[:q].downcase + '%' ],
:order => "#{method} ASC",
:select => "#{object_constant.table_name}.#{method}",
:limit => 10 }.merge!(options)

@items = object_constant.find(:all, find_options).collect(&method)

render :text => @items.join("\n")
end
end
end

end