I installed this gem: https://github.com/crowdint/rails3-jquery-autocomplete
and applied it successfully:
class TagsController < ApplicationController
autocomplete :name
end
I have a Tag model and I separate tags with a space in a tag! method:
class Post < ActiveRecord::Base
attr_accessible :title, :content, :tags_attributes
has_and_belongs_to_many :tags
def tag!(tags)
tags = tags.split(" ").map do |tag|
Tag.find_or_create_by_name(tag)
end
self.tags << tags
end
end
(It has a has_and_belongs_to_many relation with the Post model).
I created a post with these two tags: food drink.
Now the problem is that it autocompletes like this:
food
food drink
when I type food.
I want it to auto complete like this:
food
(when I type food)
and
drink
(When I type drink)
Any suggestions to fix this?
EDIT:
I’m starting to suspect that the gem is not working and this is the browser’s autocomplete.
Hey you didn’t mention any model name in the
I think it should be like this , if you are using tag model to get name of tags
Also it will be helpful for you , to see the request in browser console . It shows the status of request .
Thanks