My (long, I apologize) question is a follow-on to: How to add tagging with autocomplete to an existing model in Rails?
I am using acts-as-taggable-on
and rails3-jquery-autocomplete
, and trying to set up a system (much like Stack Overflow) where users begin to enter in a tag and suggestions appear in a drop-down box.
Goal
I am in the answers#new form and I want to see a list of tags that relate to questions. i.e. Imagine being on SO looking for new Rails questions to answer, and searching for ra
. Ruby-on-Rails
pops up, you click it, and you see a list of questions under RoR, any one of which you can answer.
These are the steps I've taken.
- Installed both gems. Both seem to work on their own.
- Added
<%= javascript_include_tag "ui/jquery.ui.position", "ui/jquery.ui.autocomplete", "autocomplete-rails.js", "rails.js", "application.js" %>
. (I already have Jquery, UI Core and UI Effects.) - Answers controller: I added at top
autocomplete :question, :tags, :full => true
. I also triedautocomplete :tag, :name, :full => true
. - Question.rb:
acts_as_taggable_on :tags
. - View:
<%= form_tag new_answer_url, :method => "get" do %>
<%= autocomplete_field_tag "tag_list", 'tags', autocomplete_question_tags_answers_path %>
<% end %>
A simple autocomplete (no tagging) works (but it only works once per page load). With tagging, no success.
Problems
With lots of experimentation (and many hours) I am getting these problems:
- I get
NameError (unitialized constant Tag)
in server response to initial entry. - With a non-taggable implementation (searching for the simple question text itself) I get a JQuery Autocomplete-style drop-down but my cursors cannot access the options with up/down. I have to click them with the mouse. Also, the dropdown doesn't disappear unless I reload the page!
- After the server responds with results once (only non-taggable is working as I mentioned), it doesn't respond again to key presses or changes in the text entry.
I would greatly appreciate any help you are able to give. I have gone through a few tutorials step-by-step but no luck today.