Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6925475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:47:39+00:00 2026-05-27T10:47:39+00:00

I’ve implemented the framework outlined in this post: How to use jquery-Tokeninput and Acts-as-taggable-on

  • 0

I’ve implemented the framework outlined in this post: How to use jquery-Tokeninput and Acts-as-taggable-on with some difficulty. This is working insofar as prepopulating with the appropriate theme and ajax search, but when I enter a new tag, it is immediately deleted when the text area loses focus. I’m not sure what I’m doing wrong. Here’s some of my relevant code:

User Model (does the tagging):

class User < ActiveRecord::Base
[...]
# tagging
acts_as_tagger

Item Model (accepts a tag):

class Item < ActiveRecord::Base
attr_accessible :title, :tag_list

#tagging functionality
acts_as_taggable_on :tags

Item Controller:

def tags 
@tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:q]}%") 
 respond_to do |format|
  format.json { render :json => @tags.collect{|t| {:id => t.name, :name => t.name }}}
 end
end

On my form partial:

<%= f.input :tag_list, :label => "Tags", :input_html => { :class => "text_field short", "data-pre" => @item.tags.map(&:attributes).to_json }, :hint  => "separate tags by a space"  %>

my routes:

get "items/tags" => "items#tags", :as => :tags
resources :items 

[almost there!!!]

the js on the form [note: the id of the element is assigned dynamically]:

<script type="text/javascript">
$(function() {
  $("#item_tag_list").tokenInput("/art_items/tags", {
    prePopulate:       $("#item_tag_list").data("pre"),
    preventDuplicates: true,
    crossDomain: false,
    theme: "facebook"
  });
});
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:47:40+00:00Added an answer on May 27, 2026 at 10:47 am

    If you still want to use Jquery TokenInput and add tags there are different ways to do it.

    1.
    This is actually from my same question; the newest answer: How to use jquery-Tokeninput and Acts-as-taggable-on

    This could go in your controller.

     def tags
        query = params[:q]
        if query[-1,1] == " "
          query = query.gsub(" ", "")
          Tag.find_or_create_by_name(query)
        end
    
        #Do the search in memory for better performance
    
        @tags = ActsAsTaggableOn::Tag.all
        @tags = @tags.select { |v| v.name =~ /#{query}/i }
        respond_to do |format|
          format.json{ render :json => @tags.map(&:attributes) }
        end
      end
    
    This will create the tag, whenever the space bar is hit.
    
    You could then add this search setting in the jquery script:
    
    noResultsText: 'No result, hit space to create a new tag',
    
    It's a little dirty but it works for me.
    

    2.
    Check out this guy’s method: https://github.com/vdepizzol/jquery-tokeninput

    He made a custom entry ability:

    $(function() {
      $("#book_author_tokens").tokenInput("/authors.json", {
        crossDomain: false,
        prePopulate: $("#book_author_tokens").data("pre"),
        theme: "facebook",
        allowCustomEntry: true
      });
    });
    

    3.
    Not to sure about this one but it may help: Rails : Using jquery tokeninput (railscast #258) to create new entries


    4.
    This one seems legit as well: https://github.com/loopj/jquery-tokeninput/pull/219

    I personally like the first one, seems easiest to get and install.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.