Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="https://github.com/mbleigh/acts-as-taggable-on" rel="nofollow noreferrer">acts_as_taggable_on</a> and <a href="https://github.com/crowdint/rails3-jquery-autocomplete" rel="nofollow noreferrer">rails3-jquery-autocomplete</a> work nicely together to make a SO like tagging system see example below. I don't think a suitable all in one option exists yet for rails.</p> <p><strong>Follow these steps to get this all installed:</strong></p> <p>1 . Backup your rails app!<br /><br /> 2 . Install <a href="https://github.com/indirect/jquery-rails" rel="nofollow noreferrer">jquery-rails</a> </p> <p>Note: You can install jQuery UI with <code>jquery-rails</code> but I chose not to.</p> <p>3 . Download and install <a href="http://jqueryui.com/download" rel="nofollow noreferrer">jQuery UI</a></p> <p>Choose a theme that will compliment your web design (be sure to test the autocomplete demo with the theme you choose, the default theme did not work for me). Download the custom zip and place the <code>[zipfile]/js/jquery-ui-#.#.#.custom.min.js</code> file into your app's <code>/public/javascripts/</code> folder. place the <code>[zipfile]/css/custom-theme/</code> folder and all files into your app's <code>public/stylesheets/custom-theme/</code> folder.</p> <p>4 . Add the following to your Gemfile and then run "bundle install"</p> <blockquote> <p>gem 'acts-as-taggable-on'<br /> gem 'rails3-jquery-autocomplete'</p> </blockquote> <p>5 . From the console run the following commands:</p> <blockquote> <p>rails generate acts_as_taggable_on:migration<br /> rake db:migrate<br /> rails generate autocomplete:install<br /></p> </blockquote> <p><strong>Make these changes in your app</strong></p> <p>Include the necessary javascript and css files in your application layout:</p> <pre><code>&lt;%= stylesheet_link_tag "application", "custom-theme/jquery-ui-1.8.9.custom" %&gt; &lt;%= javascript_include_tag :defaults, "jquery-ui-#.#.#.custom.min", "autocomplete-rails" %&gt; </code></pre> <p><strong>Controller Example</strong></p> <p>EDIT: Made changes based on Seth Pellegrino's comments. </p> <pre><code>class ArticlesController &lt; Admin::BaseController #autocomplete :tag, :name &lt;- Old autocomplete :tag, :name, :class_name =&gt; 'ActsAsTaggableOn::Tag' # &lt;- New end </code></pre> <p><strong>Model Example</strong></p> <pre><code>class Article &lt; ActiveRecord::Base acts_as_taggable_on :tags end </code></pre> <p><strong>Route.rb</strong></p> <pre><code>resources :articles do get :autocomplete_tag_name, :on =&gt; :collection end </code></pre> <p><strong>View Example</strong></p> <pre><code>&lt;%= form_for(@article) do |f| %&gt; &lt;%= f.autocomplete_field :tag_list, autocomplete_tag_name_articles_path, :"data-delimiter" =&gt; ', ' %&gt; # note tag_list above is a virtual column created by acts_as_taggable_on &lt;% end %&gt; </code></pre> <p>Note: This example assumes that you are only tagging one model in your entire app and you are only using the default tag type :tags. Basically the code above will search all tags and not limit them to "Article" tags. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload