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

  • SEARCH
  • Home
  • 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 8176957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:23:01+00:00 2026-06-06T23:23:01+00:00

Im using jquery-tokeninput, but a fork of it which allows the User to add

  • 0

Im using jquery-tokeninput, but a fork of it which allows the User to add new custom tokens (Tag) for each Resource.

Example here (Scroll down to the tag box and type a few letters. you can type ones that dont exist): http://www.tomsguide.fr/solutions/nouveau_sujet.htm

The current return value from the fork I’m using is this (new value in quotes):

16,42,'Subway',37,'McDonald\'s',734

I’m having extreme difficulty trying to handle this in Rails. This sums it up perfectly.

This is what I have so far, and its not working, probably for a lot of reasons I’m not seeing, but the main reason is that I need to create new Tag instances but not save them, that way I can somehow pass them back into the token input, and save the new Tags along with the new Resource when they submit the form. When you use Tag.new though, it doesnt create an ID.

resource.rb

attr_accessor :tokens_list

# CUSTOM TOKENS                 
def tag_tokens=(tokens)
  self.tokens_list = tokens.split(",")

  if new_custom_tokens?
    self.tokens_list.each do |token|
      tokens_list << token if token.include? "'"
    end
  end

  self.tag_ids = self.tokens_list
end

def new_custom_tokens?
  self.tokens_list.each do |token|
    return true if token.include? "'"
  end
  false
end

resources_controller.rb

def create
  @title = "Submit Resource"
  @resource = Resource.new(params[:resource])

  assign_to_global_user?

  # CUSTOM TOKENS
  if @resource.new_custom_tokens?
    custom_token_time_restriction
    # Create Tag.new
  end

  if @resource.valid?
    @resource.save
    flash[:notice] = "Your link has been successfully submitted."
    redirect_to root_url
  else
    render :action => :new
  end 
end

def assign_to_global_user?
  if user_signed_in?
    @resource.user_id = current_user.id
  else
    @resource.user_id = User.find_by_username("Global_User").id
  end
end

private

# CUSTOM TOKENS   
def custom_token_time_restriction
  limit = 7 # days
  if (@resource.user_id != User.global_user_id) and (Time.now - limit.days > User.find(@resource.user_id).created_at)
    # TODO: Check if they are anonymous or their account is newer than 7 days
  else
    flash[:notice] = "You be Logged in to add new tags, and your account must be older than #{limit} days."
    render :action => :new
  end
end

new.html.erb (for resource#new)

<div class="field">
  <%= f.label :tags %>
  <%= f.text_field :tag_tokens, "data-pre" => @resource.tags.to_json(:only => [:id, :name]), :class => :tagbox %>
</div>
  • 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-06-06T23:23:02+00:00Added an answer on June 6, 2026 at 11:23 pm

    I had the same problem. This is what I have done:

    This is the function where I return tokens of search in json format.

    tags = TagMaster.where("name LIKE ?", "%#{params[:q]}%").limit(10)
    if tags == []
      list << {"id" => "0","name"=>new_tag.rstrip}
    else
      tags.each { |tag| list << {"id" => tag.id.to_s, "name" => tag.name }}
    end
    
    respond_to do |format|
      format.json { render :json => list.to_json, :layout => false }
    end
    

    Now this will allow show you whatever you type in auto complete dropdown and on clicked it will show as a token.

    Now you can’t add any more custom tokens because any token that is not in database will return id 0 so only one custom token is allowed at this point of time.

    For that problem I did following.

    var k = jQuery.noConflict();
    k("#project_tags").tokenInput("tag_list", {
      hintText: "Enter Tags for your Project",
      noResultsText: "No Such Tags",
      searchingText: "Looking for your Tags",
      preventDuplicates: true,
      theme: "facebook",
      onAdd: function (item) {
        if (item.id == '0') {
          k.ajax({
        url: '/add_project_tag',
            data: { name: item.name },
        success:function(data) {
              k("#project_tags").tokenInput("add", {id: data, name: item.name});
              k("#project_tags").tokenInput("remove", {id: '0' });
            }
      });
        }
      }
    });
    

    As you can see here i call add_project_tag where I store that custom tag into database and it returns id of that inserted tag. So now you simply add the same token with it’s id and remove token with 0.

    So now there won’t be any token with 0 and you can add as many new token as you want.

    Hope this helps. Throw your questions if any more complications.

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

Sidebar

Related Questions

I am using Jquery tokenizer as like facebook using the following plugin http://loopj.com/jquery-tokeninput/ which
im following the railscasts using jquery tokeninput http://railscasts.com/episodes/258-token-fields-revised in creating autocomplete tag tokens and
I am using Jquery Tokeninput to select multiple values but when i tried to
I'm using jQuery with tokeninput Plugin. I initialize it with: $(input#id).tokenInput(url, { defaultValue: Very
Using jQuery timepickr: http://archive.plugins.jquery.com/project/jquery-timepickr Having included these files: jquery-1.7.1.min.js jquery-ui-1.8.21.custom.min.js ui.timepickr.js And getting this
Using Jquery TableSorter, I am creating a custom parser to sort elapsed time <td>
I'm using tokenInput jquery plugin for autocomplete. This script is working fine <script type=text/javascript>
Using jquery I have a clicking tab mechanism that are nothing but anchor tags
I'm using the jquery tokeninput plugin from loopj.com Here is my JS File: $(document).ready(function()
I am using jQuery Tokeninput autocomplete plugin for the list of programming languages and

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.