This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 50a24a0c927ec953329fddb1cc86977dda3bf374
tree ab7ebae84c7b388b6a5c4092cbc65e546c5f08c2
parent 82e2cebeb8af0173e2fa63301258a9fc874eca95
tree ab7ebae84c7b388b6a5c4092cbc65e546c5f08c2
parent 82e2cebeb8af0173e2fa63301258a9fc874eca95
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sun Oct 26 01:23:40 -0700 2008 | |
| |
CHANGELOG | Tue Jan 20 01:43:28 -0800 2009 | |
| |
README.markdown | ||
| |
Rakefile | Tue Jan 20 01:43:28 -0800 2009 | |
| |
example_js/ | ||
| |
init.rb | Tue Jan 20 01:43:28 -0800 2009 | |
| |
lib/ | ||
| |
spec/ |
README.markdown
- simple unobstrusive autocomplete
- JS-library-independent
- Controller and Model helpers
Install
script/plugin install git://github.com/grosser/simple_auto_complete.git
copy javascripts/css from example folder OR use your own
Examples
Controller
By default, autocomplete_for limits the results to 10 entries,
and sorts by the autocomplete field.
class UsersController < ApplicationController
autocomplete_for :user, :name
end
autocomplete_for takes a third parameter, an options hash which is used in the find:
autocomplete_for :user, :name, :limit => 15, :order => 'created_at DESC'
With a block you can generate any output you need(passed into render :inline):
autocomplete_for :post, :title do |items|
items.map{|item| "#{item.title} -- #{item.id}"}.join("\n")
end
View
<%= f.text_field :auto_user_name, :class => 'autocomplete', 'autocomplete_url'=>autocomplete_for_user_name_users_path %>
Routes
map.resources :users, :collection => { :autocomplete_for_user_name => :get}
JS
use any library you like (includes examples for jquery jquery.js + jquery.autocomplete.js + jquery.autocomplete.css)
jQuery(function($){//on document ready
//autocomplete
$('input.autocomplete').each(function(){
var $input = $(this);
$input.autocomplete($input.attr('autocomplete_url'));
});
});
Records (Optional)
- converts an auto_complete form field to an association on assignment
- Tries to find the record by using
find_by_autocomplete_xxxon the records model - unfound record -> nil
- blank string -> nil
- Controller find works independent of this find
Example for a post with autocompleted user name:
class User
find_by_autocomplete :name # User.find_by_autocomplete_name('Michael')
end
class Post
has_one :user
autocomplete_for(:user, :name) #--> f.text_field :auto_user_name
# OR
autocomplete_for(:user, :name, :name=>:creator) #--> f.text_field :auto_creator_name (creator must a an User)
end
Authors
Contributors (alphabetical)
Copyright (c) 2008 Michael Grosser, released under the MIT license
Original: Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license








