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 (
| name | age | message | |
|---|---|---|---|
| |
CHANGELOG | Tue Jan 20 01:43:28 -0800 2009 | |
| |
README | Fri Sep 26 09:02:57 -0700 2008 | |
| |
Rakefile | Fri Sep 26 09:02:57 -0700 2008 | |
| |
example%20js/ | Fri Sep 26 09:02:57 -0700 2008 | |
| |
init.rb | Fri Sep 26 09:02:57 -0700 2008 | |
| |
lib/ | Fri Sep 26 09:24:01 -0700 2008 | |
| |
test/ |
README
Example:
### Controller
class PostsController < ApplicationController
autocomplete_for :user, :name
end
# Options
By default, autocomplete_for limits the results to 10 entries,
and sorts by the given field.
autocomplete_for takes a third parameter, an options hash to
the find method used to search for the records:
autocomplete_for :user, :name, :limit => 15, :order => 'created_at DESC'
# Block
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}
### Records
class User
find_by_autocomplete 'name' --> self.find_by_autocomplete_name
end
class Post
has_one :user
autocomplete_for('user','name') --> auto_user_name= + auto_user_name
end
add autocomplete_for to your models to directly transform field values to objects
and transform these objects back into field values for display
- uses find_by_autocomplete_#{name} to find the wanted record
- unfound record -> nil
- blank string -> nil
### 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'));
});
});
Copyright (c) 2008 Michael Grosser, released under the MIT license
Original: Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license








