# Simple auto-complete tutorial

**URL:** <https://www.ruby-forum.com/t/simple-auto-complete-tutorial/163292>\
**Category:** Rails\
**Created:** [March 18, 2009, 11:09pm UTC](https://www.ruby-forum.com/t/simple-auto-complete-tutorial/163292 "2009-03-18T23:09:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [March 18, 2009, 11:09pm UTC](https://www.ruby-forum.com/t/simple-auto-complete-tutorial/163292/1 "2009-03-18T23:09:28Z")

</div>

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 %\>:&nbsp;\<%= 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 }
