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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:44:21+00:00 2026-06-16T05:44:21+00:00

I’m trying to set up a search-as-you-type form with Tokeninput, with help from Ryan

  • 0

I’m trying to set up a search-as-you-type form with Tokeninput, with help from Ryan Bates’ Railscast. Unfortunately, I’m having trouble figuring it out with a self-referential association.

In my models:

class Skill < ActiveRecord::Base
  attr_accessible :skill_relationship_attributes, :prereq_tokens
  attr_reader :prereq_tokens

  has_many :skill_relationships
  has_many :prereqs, :through => :skill_relationships
  has_many :inverse_skill_relationships, :class_name => 'SkillRelationship', :foreign_key => "prereq_id"
  has_many :inverse_prereqs, :through => :inverse_skill_relationships, :source => :skill

  accepts_nested_attributes_for :skill_relationships, :allow_destroy => true

  def prereq_tokens=(ids)
    self.prereq_ids = ids.split(",")
  end
end

class SkillRelationship < ActiveRecord::Base
  attr_accessible :skill_id, :prereq_id, :skill_attributes, :prereq_attributes

  belongs_to :skill
  belongs_to :prereq, :class_name => 'Skill'
end

And I feebly put together a form:

<%= form_for skill do |f| %> 
  <%= f.label :prereq_tokens, "Prerequisites" %><br/>
  <%= f.text_field :prereq_tokens, data: {load: Skill.all} %>       
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

I do get a nicely styled text field, but it doesn’t find anything when it searches and I’m not really sure where to go from here. Any ideas?

  • 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-16T05:44:22+00:00Added an answer on June 16, 2026 at 5:44 am

    I figured this one out! First, I removed “data: {load: Skill.all}” from the form, because I wanted it to work through thinking_sphinx rather than my entire database. Then – and here was the key – I specified propertyToSearch and queryParam in my coffeescript:

    jQuery ->
      $('#skill_prereq_tokens').tokenInput '/skills.json'
        theme: 'facebook'
        propertyToSearch: 'title' // :title is the attribute in my Skill model that I want to show up in the list
        queryParam: 'search' // :search is the parameter that gets passed to thinking_sphinx
    

    And voila! It turned out to be more a thinking_sphinx issue than anything to do with my self-referential associations.

    It’s important to note that specifying the title attribute with propertyToSearch only determines which attribute gets to represent each skill and does not prevent thinking_sphinx from using other attributes from its index.

    It doesn’t work exactly like a Facebook input field though, since thinking_sphinx by default only does whole-word search. In other words, if I’m looking for a skill called “Boxing” and I type in “box” or even “boxin”, I’ll get nothing. Only when I finally type in the full word boxing “boxing” will the skill be returned in the list. It’s possible to configure thinking_sphinx to index prefixes, so that it’ll return results from partial words, like Facebook does – but if you’re indexing a large database, you probably don’t want to do that, because your index will blow up crazy fast. That’s probably a significant part of the reason why Facebook caps everyone at 5000 friends, apart from the fact that no one has 5000 friends.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.