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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:00:05+00:00 2026-06-07T11:00:05+00:00

I am using Thinking Sphinx to run searches and I get the appropriate ActiveRecord

  • 0

I am using Thinking Sphinx to run searches and I get the appropriate ActiveRecord Models fine. The problem is, I want to create an appropriate link path and text on each model, then send the info to the browser in the form of JSON, via AJAX. I am using the following to build those link attributes:

In the controller:

class FindController < ApplicationController
  def tag_results
    @results = ThinkingSphinx.search(params[:terms])
    @results.each do |result|
      result.build_ajax_response
    end
    respond_to do |format|
      format.html
      format.json { render :json => @results }
    end
  end
end


In the model:

class TaggedItem < ActiveRecord::Base
  attr_accessible :name
  attr_accessor :search_link, :search_text

def build_ajax_response self.search_link = Rails.application.routes.url_helpers.tagged_item_path(self.id) self.search_text = self.name end end


The resulting json object doesn’t have either of the search_* attributes listed, much less have a value for them. I’ve tried using @search_link as well as just search_link in the build_ajax_response method.

Am I doing this wrong? Could there be something else interfering?

  • 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-07T11:00:09+00:00Added an answer on June 7, 2026 at 11:00 am

    Rails’ default to_json doesn’t know about those extra non active record attributes you’ve added. The easiest possible thing is probably to specify them as extra methods to include:

    format.json { render :json => @results.to_json(:methods => [:search_link, :search_text]) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Started using thinking sphinx today and I'd like to know what's going wrong here:
I'm searching in two different modes using Thinking Sphinx: Full search on a single
I am using Thinking Sphinx for a Rails application. Everything works perfectly. I just
I'm using Thinking Sphinx in a Rails application combined with the jQuery autocomplete plugin
I have two models Post and comment and i want to search both using
I am using Sphinx with the Thinking Sphinx plugin to search my data. I
I'm using a Sphinx search engine to perform my searches in a Rails project,
I'm attempting to get Thinking Sphinx working w/ Delayed Jobs but I am not
I'm running sphinx, thinking sphinx on our rails3 application. I'm also using passenger on
I am using Ruby on Rails and the Thinking-Sphinx Gem with Sphinx as the

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.