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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:36:50+00:00 2026-05-25T02:36:50+00:00

I have a simple jquery auto complete search in my Rails 3 app based

  • 0

I have a simple jquery auto complete search in my Rails 3 app based on the one in Railscasts episode #240 that filters a list of location objects on the location index page by rendering a partial using jquery.

In the partial (_locations.html.erb), the location objects are each wrapped in their own div and are styled to look like a clickable element. When the user clicks one of them, I’d like it to do two things:

  1. Change the selected div’s background color to show that it’s selected (this part already works fine).

  2. Render content that’s specific to the selected object in an empty div. A link to the show page will be included in the rendered content. This will basically function like a quickview/preview.

This all changes dynamically according to the current selection without refreshing the page.

My Problem:

I’m having troubles with the second point. I can’t seem to get the partial to render when the location element is clicked. I’ve tried a lot of different things over the past week. There are a couple examples that have gotten me close (Rails 3 – link_to to call partial using jquery ajax, Render a partial in rails using jquery) in addition to many others that aren’t as relevant but follow a similar strategy.

I suspect it might be a problem in the way I’m calling a partial within a partial, but I’m not sure. I included my code below. When I try it out, I’m taken to a blank page with the following address: localhost:3000/locations/1/show_quickview

Thanks for any help in advance. Also, thanks for helping me get this far – you guys are great!

index.html.erb

<%= form_tag locations_path, :method => 'get', :id => "locations_search" do %>
<p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
</p>
<% end %>
<div id="quickview"></div>     #placed here only for testing out
<div id="locations">
    <%= render 'locations' %>
</div>

_locations.html.erb

<% @locations.each do |location| %>
<div class="location">
    <h4><%= link_to location.name, show_quickview_location_path(:id => location.id), :remote => true %></h4>
</div>
<% end %>

_quickview.html.erb

<p><%= location.name %></p>     #keeping it simple for now

routes.rb

  resources :locations do
    member do
      get 'show_quickview'    
    end
  end

locations_controller.rb

  def show_quickview
    respond_to do |format|
      format.js { render :layout => false }
    end
  end

show_quickview.js.erb

$("#quickview").html("<%= escape_javascript(render(:partial => "quickview", :locals => { :location => location }))) %>");

application.js

$(function() {
  $("#locations_search input").keyup(function() {
    $.get($("#locations_search").attr("action"), $("#locations_search").serialize(), null, "script");
    return false;
  });
    $(".location").click(function() {
        $(".location").not(this).removeClass('location-clicked h4');
        $(this).toggleClass('location-clicked h4');
    });
});
  • 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-25T02:36:50+00:00Added an answer on May 25, 2026 at 2:36 am

    Well after stepping away from this problem for a while, I finally figured out the problems (there were multiple). Finally some closure!!

    1. I had errors in the jquery code that render the partial.
    2. I wasn’t defining anything in my controller method.

    The greatest thing I learned from this is the power of the server logs. If anyone runs into a similar issue, check your server logs – especially when debugging jquery. What a useful tool! Depending on what you are doing (like rendering a partial), rails might not render your error message in your browser, but it may still appear in your server logs. For me, it was tossing up an error related to my partial. Hopefully down the road this saves at least one person a bit of time.

    Here’s the final working code below. Please note that I changed some of the naming conventions and html structure too.

    index.html.erb

    <%= form_tag locations_path, :method => 'get', :id => "locations_search" do %>
    <p>
      <%= text_field_tag :search, params[:search] %>
      <%= submit_tag "Search", :name => nil %>
    </p>
    <% end %>
    
    <div id="sidebar">
      <div id="locations">
        <%= render 'locations' %>
      </div>
    </div>
    <div id="content">
      <div id="location-quickview">
        <h2>Select a Country...</h2>
      </div>
    </div>
    

    _locations.html.erb

    <% @locations.each do |location| %>
    <div class="location">
      <h4><%= link_to location.name, quickview_location_path(:id => location.id), :remote => true %></h4>
    </div>
    <% end %>
    

    _quickview.html.erb

    <p><%= location.name %></p>
    

    routes.rb

    resources :locations do
      member do
        get 'quickview'    
      end
    end
    

    locations_controller.html.erb

    def quickview
      @location = Location.find(params[:id])
    
      respond_to do | format |  
        format.js {render :layout => false}  
      end
    end
    

    quickview.js.erb

    $("#quickview").html("<%= escape_javascript(render(:partial => "quickview", :locals => {:location => @location})) %>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

all i need is a very simple auto complete that suggests words that have
I have read several articles/questions/forums discussing the best auto-complete plugin for jQuery. After trying
I have been struggling to get a simple autocomplete working with my Rails app
I have a simple login form that captures username/password with some simple Javascript (JQuery)
I have a simple jQuery/PHP autocomplete text box that gets the matches from mySQL.
I have a simple HTML. I am using the JQuery for AJAX purpose. Now,
I have a simple html page with a div. I am using jQuery to
I have a simple html block like: <span id=replies>8</span> Using jquery I'm trying to
Should simple JavaBeans that have only simple getters and setters be unit tested?? What
I have a simple webform that will allow unauthenticated users to input their information,

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.