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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:23:58+00:00 2026-06-01T13:23:58+00:00

I am trying to set up jQuery autocomplete in Rails 3.2.0. I have it

  • 0

I am trying to set up jQuery autocomplete in Rails 3.2.0. I have it working fine if I set up an array in javascript as the data source. My problem is that the search terms will eventually become too many to load during page load. I am trying to get the remote data source set up but it is failing to populate the content on the page.

The data is being returned, but the selections are not populating. The vast majority of this code is straight from the jQuery UI demos site.

What am I missing?

$( "#tags" )
    // don't navigate away from the field on tab when selecting an item
    .bind("keydown", function( event ) {
        if ( event.keyCode === $.ui.keyCode.TAB &&
          $( this ).data( "autocomplete" ).menu.active ) {
              event.preventDefault();
          }
     })
     .autocomplete({
         source: function( request, response ) {
             $.getJSON( "get/tags", {
                 term: extractLast( request.term )
             }, response.name );

          },
          search: function() {
              // custom minLength
              var term = extractLast( this.value );
              if ( term.length < 2 ) {
                  return false;
              }
          },
          focus: function() {
              // prevent value inserted on focus
              return false;
          },
          select: function( event, ui ) {
              var terms = split( this.value );
              // remove the current input
              terms.pop();
              // add the selected item
              terms.push( ui.item.value );
              // add placeholder to get the comma-and-space at the end
              terms.push( "" );
              this.value = terms.join( ", " );
              return false;
          }
      });
  • 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-01T13:23:59+00:00Added an answer on June 1, 2026 at 1:23 pm

    I found my problem. Silly me. Reading ALL the documentation on the autocomplete plugin is helpful. My problem was that I was not providing a proper “termed” JSON array.

    Quoted from the jQuery UI page

    An Array of Objects with label and value properties:
    [ { label: “Choice1”, value: “value1” }, … ]

    So creating the rendered JSON in your Rails app like this:

    def get_tags
        @tags = Tag.where(['name LIKE ?', "#{params[:term]}%"])
        @tags_hash = []
    
        @tags.each do |tag|
          @tags_hash << { label: tag.name }
        end
    
        render json: @tags_hash
    end
    

    Also in my code above the $.getJSON should be defined like so:

    $.getJSON( "get/tags", {
        term: extractLast( request.term )
        }, response );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set a range for a jquery datepicker that I have on
I have a recursive nodes that I'm trying to set up for jquery-checktree. The
I am trying to set up an auto-complete search form with jQuery. I would
I'm trying to set the scroll with jQuery / JavaScript. I'm having trouble figuring
I am trying to upload multiple images and I have a jquery plugin set
Recently I started using https://github.com/crowdint/rails3-jquery-autocomplete It works great, but I was trying to set
I'm trying to set conditions on a jQuery event. I have an input element
I am trying to set up an array in jQuery and I then need
I am trying to set source of a dynamically inserted iframe with jquery, it
I am trying to set up a callback in jQuery that correctly binds 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.