Simple auto-complete tutorial


#1

I’m putting this here because it took too long to set up:

==============================

Things you’ll need for auto_complete since everyone else was too lazy to
write down:

Example model is ‘list’
Example field is ‘name’

Controller

auto_complete_for :list, :name
skip_before_filter :verify_authenticity_token, :only =>
[:auto_complete_for_list_name]

view (edit.html.erb)

<%= javascript_include_tag :all, :cache => true %>
<% form_for(@list) do |f| %>
<%= f.error_messages %>

New <%= f.label :name %>: <%= text_field_with_auto_complete :list, :name %> <%= f.submit "Update" %> <% end %>

layout

<%= javascript_include_tag :defaults %>

routes.rb

map.auto_complete ‘:controller/:action’,
:requirements => { :action => /auto_complete_for_\S+/
},
:conditions => { :method => :get }