RailsCasts Pro episodes are now free!
Learn more or hide this
There is a newer version of this episode, see the revised episode.
Update: As Stephen Gerstacker pointed out in the comments, the :param_name option is preferred over the :with option. See the code below for an example.
script/plugin install git://github.com/rails/auto_complete.git
def category_name category.name if category end def category_name=(name) self.category = Category.find_or_create_by_name(name) unless name.blank? end
def index @categories = Category.find(:all, :conditions => ['name LIKE ?', "%#{params[:search]}%"]) end
<p> <%= f.label :category_name %> <%= text_field_with_auto_complete :product, :category_name, { :size => 15 }, { :url => formatted_categories_path(:js), :method => :get, :param_name => 'search' } %> </p>
<%= auto_complete_result @categories, :name %>