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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:18:12+00:00 2026-06-17T07:18:12+00:00

I am trying to put a search facility on a Users Index page in

  • 0

I am trying to put a search facility on a Users Index page in a Rails application (similar to that in Michael Hartl’s Rails Tutorial) and am using the Ransack gem to do the search. It’s just a simple search on the user’s name that I’ve implemented as follows:

Users Controller:

def index
  @title = "All Users"
  @search = User.search(params[:q])
  @users = @search.result.paginate(page: params[:page])
end

Index View:

<%= search_form_for @search do |f| %>
    <%= f.text_field :name_cont, id: :search_box %>
    <%= f.submit "Search" %>
<% end %>

The problem is this: when I go into the Index page and search for a user that actually appears there, they might not come up. For instance, Mrs. Linnie Bahringer appears in the original list, but not in the search results when I search for ‘lin’.

[I wanted to show pictures here, but can’t as I need five more reputation points.]

Naturally, I thought that Ransack was somehow botching the query. However, when I output the @users variable to the page, by putting

<%= @users.each do %>
<% end %>

into the view, the ‘missing’ user is in the list of names and, lo and behold, appears in the list of results!

Does anyone know why this might be happening and how I can end up with the ‘right’ set of results without printing out the contents of the @users variable to the screen? I have tried taking the ‘=’ sign out of the @users.each do line as a hack, but the behaviour returns to that mentioned in the problem above.

Thanks very much in advance for any help you can give!

PS I should probably show my entire view file just in case it might be of use:

<% provide :title, 'All Users' %>
<h1>All Users</h1>

<div class="span3 offset9   btn-group">
<%= search_form_for @search do |f| %>
    <%= f.text_field :name_cont, id: :search_box %>
    <%= f.submit "Search" %>
<% end %>
</div>

<%= will_paginate %>

<!-- This bit is only in to show the value of @users -->
<%= @users.each do %>
<% end %>
<!-- Extra bit ends. -->

<ul class="users">
<%= render @users %>
</ul>

<%= will_paginate %>
  • 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-17T07:18:13+00:00Added an answer on June 17, 2026 at 7:18 am

    Well, I feel a bit of a chump. After working on another problem for a while, it occurred to me that it might just be the display of the information that was wrong. Sure enough, when I checked the HTML source (which I’m surprised I forgot to do before posting the question), the ‘missing’ user was in it.

    I solved the matter by putting a non-breaking space in a div above the list (pretty much where the @users.each do bit is) then setting the CSS for that div to have a clear: both; in it.

    Here’s my updated view:

    <% provide :title, 'All Users' %>
    <h1>All Users</h1>
    
    <div class="span3 offset9   btn-group">
    <%= search_form_for @search do |f| %>
        <%= f.text_field :name_cont, id: :search_box %>
        <%= f.submit "Search" %>
    <% end %>
    </div>
    
    <div id="clear-space">
    &nbsp;
    </div>
    
    <div id="all_users_list">
    <%= will_paginate %>
    <ul class="users">
        <%= render @users %>
    </ul>
    <%= will_paginate %>
    </div>
    

    As I say, it was a silly mistake to make, but we’re all chumps at least once a day!

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

Sidebar

Related Questions

I'm using MongoDB with Mongoid and trying to put in place a rudimentary search
I am trying to create an application that allows the user to search a
So I'm trying to create a system to index users in a search database,
I am trying to put an index on a column that will hold URLs.
I am trying to put full text search working on SQL Server 2008, however
I'm trying to use Google's Images API to search an image and put it
I'm trying put an if statement directly into a select field in rails, with
Trying to put a regex expression together that returns the string between _ and
I trying to put together an Android app that will take a picture and
Using the rails button_to helper I'm trying to run the update method in a

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.