Auto-complete checkbox in Rails

My (long, I'm sorry) question is a continuation: How do I add auto-complete tagging to an existing model in Rails?

I use acts-as-taggable-on and rails3-jquery-autocomplete and try to set up a system (like a stack overflow) where users start to enter a tag and the sentences are displayed in a drop-down list.

purpose

I'm in the answer #new form, and I want to see a list of tags related to questions . For example, imagine you are on SO looking for new Rails questions to answer and search for ra . Ruby-on-Rails pops up, you click on it, and you see a list of questions in RoR, any of which you can answer.

These are the steps that I have taken.

  • Both gemstones are set. 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.)
  • Answer controller: I added at the top autocomplete :question, :tags, :full => true . I also tried autocomplete :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 %>

Simple autocomplete (without tags) works (but it only works once per page load). Noted with no success.

Problems

With a lot of experimentation (and many hours) I get the following problems:

  • I get a NameError (unitialized constant Tag) in the server response to the initial entry.
  • With a tagless implementation (to search for the simplest question text), I get a drop-down list in the JQuery autocomplete style, but my cursors cannot access the up / down options. I have to click their mouse. In addition, the dropdown does not disappear if I do not reload the page!
  • After the server responds once to the results (only those that were not tagged, as I already mentioned), it no longer responds to keystrokes or changes to the text element.

I would really appreciate any help you can give. I went through several textbooks in stages, but today, no luck.

+7
source share
2 answers

I know that it answers only one of your questions, but I was able to solve the "unified constant tag" problem by explicitly specifying the class name in my controller:

autocomplete :tag, :name, :class_name => 'ActsAsTaggableOn::Tag'

It seems that some changes to the act_as_taggable_on library violated the basic assumption that the Tag class exists.

Besides this, I noticed some strange behavior when I didn’t have jquery-ui css entered correctly on the page - did you confirm that everything is connected correctly?

+4
source

One thing I notice that you are missing is your routes. I should have done something like this:

 resources :resources do get :autocomplete_resource_tag, :on => :collection end 

In my _form.html.erb

 <%= f.autocomplete_field :tag_list, autocomplete_resource_tag_resources_path %> 

Now my problem is that autocomplete still doesn't like me

 SQLite3::SQLException: no such column: resources.tag: SELECT resources.id, resources.tag FROM "resources" WHERE (LOWER(resources.tag) LIKE 'woo%') ORDER BY resources.tag ASC LIMIT 10 Completed 500 Internal Server Error in 1ms ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: resources.tag: SELECT resources.id, resources.tag FROM "resources" WHERE (LOWER(resources.tag) LIKE 'woo%') ORDER BY resources.tag ASC LIMIT 10): 
0
source

All Articles