# Using
#
# http://github.com/rails/auto_complete/tree/master for auto_complete
# and
#http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids for tagging.
# View
<%= f.label :tag_list %>
<%= text_field_with_auto_complete :snippet, :tag_list, {},
{:with => "'tag=' + $('snippet_tag_list').value",
:method=>"get", :url => formatted_tags_url("js"), :tokens => ","} %>
# Controller
class TagsController < ApplicationController
def index
respond_to do |format|
format.html{@tags = Snippet.tag_counts(:conditions => ["public = ?", true])}
format.js do
tag = params[:tag].downcase.split(",").last.strip
find_options = {
:conditions => [ "LOWER(name) LIKE ?", '%' + tag+ '%' ],
:order => "name ASC",
:limit => 10 }
@items = Tag.find(:all, find_options)
render :inline => "<%= auto_complete_result @items, 'name' %>"
end
end
end
end