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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:38:29+00:00 2026-05-28T16:38:29+00:00

Started using thinking sphinx today and I’d like to know what’s going wrong here:

  • 0

Started using thinking sphinx today and I’d like to know what’s going wrong here:

Here is my controller:

class SearchesController < ApplicationController
   def index
     @user = User.search params[:search]
   end
end

view:

<%= form_tag searches_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>


<%= @user %>

user model

  # thinking sphinx
  define_index do
    indexes username
    indexes email
  end

browser:

[#<User id: 35, email: "elna@hodkiewicz.net", encrypted_password: "$2a$10$4TCbzA3FLel4uZIAyILHVOFPNqyqShDEMPpv0FHsS24I...", password_salt: "$2a$10$4TCbzA3FLel4uZIAyILHVO", username: "yasmin35", created_at: "2012-01-24 10:01:38", updated_at: "2012-01-24 10:01:38", password_reset_token: nil, password_reset_sent_at: nil, email_change_token: nil, email_change_sent_at: nil>] 

I assumed because it found the user I could pull what ever info I wanted from that hash, so I tried this just as a test:

<%= @user.username %>

and got this:

undefined method `username' for #<ThinkingSphinx::Search:0x0000010497e258>

I’m certain I expecting thinking sphinx to work the same way my rails find methods do but I guess they don’t. How would I achieve what I’m trying to achieve?

I would like to find a user by username or email which is working..but once I’v got that info ..use it to access associations such as the users profile and photos… so basically just use sphinx find the user then do things the way I would without sphinx..

I’m wondering is there any point using sphinx to allow my users to search for another user by email or username..? country etc..

A user has one profile and many photos. I thought by finding the user first I could then take advantage of their associations without sphinx but I was wrong.

Someone please enlighten be. I’d really appreciate it.

Kind regards

  • 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-28T16:38:30+00:00Added an answer on May 28, 2026 at 4:38 pm

    ThinkingSphinx returns an array of results by default, which is why that User object is wrapped in [ ] square brackets.

    This is the same way that a User.where(:something => true) statement works in Rails in that you need to call .first on the search or iterate over the results. Otherwise, you are calling .username on an array object which won’t work.

    In this case, you should be iterating over the result set:

    class SearchesController < ApplicationController
       def index
         # plural since we could get multiple users returned
         @users = User.search params[:search]
       end
    end
    

    and your view would be

    <% @users.each do |u| %>
      <%= u.username %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started to learn C (using Thinking In C ) and I'm wondering
i started using nginx upload module (which creates upload files like /tmp/000121545) but i
I've just started using Python and I was thinking about which notation I should
I just started thinking about using the NHibernate second level cache in one of
I recently started using Mercurial and like the way I have VCS protection for
I started using subversion for one of my projects and it would be absolutely
I started using NetBeans for Python development, and so far it looks pretty good.
I started using Sandcastle some time ago to generate a Documentation Website for one
I started using Core Data for iPhone development. I started out by creating a
I started using bundler (which is to my eyes a pure disaster). Now I

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.