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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:46:14+00:00 2026-05-23T23:46:14+00:00

Im trying to use the jquery tokeninput found here: http://loopj.com/jquery-tokeninput/ Following the guide from

  • 0

Im trying to use the jquery tokeninput found here: http://loopj.com/jquery-tokeninput/ Following the guide from railcasts: http://railscasts.com/episodes/258-token-fields

By default, it required a ‘name’ column on the table/json..

Any way to customize to change it to something else (in my case, ‘account_number’)?

(in the reailcast, he says if you dont have a ‘name’ column, youll require extra customization)

  • 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-23T23:46:14+00:00Added an answer on May 23, 2026 at 11:46 pm

    The magical lines are

    <%= f.text_field :author_tokens, "data-pre" => @book.authors.map(&:attributes).to_json %>
    

    and

    format.json { render :json => @authors.map(&:attributes) }
    

    These lines convert the data read from table into the json which jquery-tokeninput can understand. It passes on all the data from the model into, jquery-tokeninput, but it is not necessary. Tokeninput, only needs two fields,

    1. id -> for each selected token, this is posted along with form
    2. name -> used as label of the token

    If you don’t want to have a name field in your model, and want to use account_number as the label, you can do it like following:

    <%= f.text_field :author_tokens, "data-pre" => @book.authors.collect {|author| {:id => author.id, :name => author.account_number } } %>
    

    and

    format.json { render :json => @authors.collect {|author| {:id => author.id, :name => author.account_number } }
    

    Basically, change the json passed to tokeninput. Pass accoun_number as name.

    Update:

    Change this line to something which better suits you:

    @authors = Author.where("name like ?", "%#{params[:q]}%")
    

    One suggestion may be:

    @authors = Author.where("name like ?", "#{params[:q]}%")
    

    Remove the first %, but really depends on your data type and all.

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

Sidebar

Related Questions

I am trying to use jQuery's ajax functionality to update data from a web
I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint
im trying to use jquery tools tooltip ( http://flowplayer.org/tools/tooltip.html#events)on a form to show hints
I'm trying use jquery to remove a class from an element (not knowing ahead
I am trying to use jquery to do an animated scroll from one div
I am trying to use jQuery .load() to get straight html from a asmx
I'm trying to use jQuery to format code blocks, specifically to add a <pre>
I am trying to use JQuery in my ASP.Net 2.0 website in this scenario:
I'm trying to use jQuery.scrollTo plugin with accordion (where one block expands after clicking
I'm trying to use jQuery UI tabs much like a Master Page in ASP.Net.

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.