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 7960941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:53:44+00:00 2026-06-04T04:53:44+00:00

im following the railscasts using jquery tokeninput http://railscasts.com/episodes/258-token-fields-revised in creating autocomplete tag tokens and

  • 0

im following the railscasts using jquery tokeninput

http://railscasts.com/episodes/258-token-fields-revised

in creating autocomplete tag tokens and have successfully done so. however, ive been trying to add a count attribute, very similar to stack overflows tags counter.

i have in my tags#index

    @tags = Tag.order(:name)
    #@tags = Tag.order(:name).where("name like ?", "%#{params[:term]}%")
    respond_to do |format|
        format.html
        format.json { render json: @tags.tokens(params[:q]) }
    end

when i render, it calls my tokens method which is…

  def self.tokens(query)
    tags = where("name like ?", "%#{query}%")
    if tags.empty?
        [{id: "<<<#{query}>>>", name: "New: \"#{query}\""}]
    else
        puts tags.inspect
        tags
    end
  end

if i type the word ‘steelswarm’ and inspect the tags that gets returned, on my console it says…

[#<Tag id: 4, name: "steelswarm", created_at: "2012-05-11 01:49:55", updated_at: "2012-05-11 01:49:55", count: 2>]

when the user starts typing the word ‘steelswarm’ i want the dropdown to display ‘steelswarm x 2’ since it has a count of two.

ive tried doing

tags.map{ |tag| {:label => "#{tag.name} x #{tag.count}", :value => tag.name} }

in my else statement but the drop down stops rendering. it cant even find the first letter anymore. what am i doing wrong?

don’t the :label and :value attributes belong to jquery as a whole?

ive also been looking at the options from

http://loopj.com/jquery-tokeninput/

but i cant seem to find something that would work or at least i could think of…
sorry im not very familiar with json and jquery so help would be much appreciated = )

thank you.

  • 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-04T04:53:45+00:00Added an answer on June 4, 2026 at 4:53 am

    i fixed it. it seems like the token only has an :id and :name attribute. so i did..

    tags.map{ |tag| {  id: "#{tag.id}", name: "#{tag.name} # #{tag.count}" } }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been following Ryan Bates Railscast on Subdomains http://railscasts.com/episodes/221-subdomains-in-rails-3 and using lvh.me to serve
I am creating request specs following the Railscast at http://railscasts.com/episodes/257-request-specs-and-capybara In my application, users
I'm following Railscast 88 to create a dynamic dependent dropdown menu. http://railscasts.com/episodes/88-dynamic-select-menus I'm rendering
Im following the casts http://railscasts.com/episodes/314-pretty-urls-with-friendlyid?autoplay=true on friendly_id Having a user model with field login
I'm following this tutorial: http://railscasts.com/episodes/253-carrierwave-file-uploads or atleast I want to but would like to
I'm following a Rails cast to implement subscription billing. It's here: http://railscasts.com/episodes/288-billing-with-stripe My code
ok, I've been following: http://railscasts.com/episodes/196-nested-model-form-part-1 Here are the steps I've had to accomplish so
Im trying to use the jquery tokeninput found here: http://loopj.com/jquery-tokeninput/ Following the guide from
I built an authentication system for my app following these Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/274-remember-me-reset-password
It is easy, following this railscast http://railscasts.com/episodes/240-search-sort-paginate-with-ajax to be able to create a table

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.