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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:15:11+00:00 2026-06-19T00:15:11+00:00

I know I had this search function working only a moment ago but have

  • 0

I know I had this search function working only a moment ago but have been redoing my search and navbar with bootstrap and now it looks good but the search function is not working!! I think it’s something in the index action? All it does is, well, nothing. Perhaps it’s not submitting the form? – how can I check this?

VIEWS
*guidelines_controller.rb*

 def index
    @guidelines = Guideline.order(:title).all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @guidelines }
    end
    @search = Sunspot.search(Guideline) do  
    fulltext params[:search]  
  end  
  @guidelines = @search.results 
  end

layouts/application.html.erb

<%= form_tag guidelines_path, :class => 'navbar-search', :method => :get do %>  

    <%= text_field_tag :search, params[:search], :class => 'search-query', :placeholder=>"Search" %> 

MODELS
guideline.rb

searchable do
    text :title, :default_boost => 2
    text :subtitle
  end
  • 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-19T00:15:12+00:00Added an answer on June 19, 2026 at 12:15 am

    I am not a Sunspot expert, but your controller method is a bit strange. Why do you render your view before calling Sunspot?

    Moreover, why do you fetch all guideline rows (Guideline.order(:title).all) ?

    I have refactored your method assuming you want to search with Sunspot if a search condition (params[:search]) is given. Otherwise all rows are fetched.

    def index
      if params[:search].present?
        @search = Sunspot.search(Guideline) do  
          fulltext params[:search]
        end
    
        @guidelines = @search.results
      else
        @guidelines = Guideline.order(:title).all
      end
    
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @guidelines }
      end
    end
    

    By the way, if the Guideline model contains a lot of rows, you should consider limiting the number of rows (limit or pagination).

    EDIT

    Here is a screencast about Sunspot #278 Search with Sunspot

    Maybe you forgot to reindex your search engine?

    rake sunspot:reindex
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question had been asked a hundred times, but I have difficulties
I know that this question had already been asked a couple of times before,
It was working few days ago, don't know what had went wrong... **undefined method
I have seen in a google search that some other people have had this
I have tried to search this but to no avail. The code i have
I know I've had this problem before so I'm really frustrated. I've got the
OK i am really struggling with this! I know had to add an image
I had to de-compile some code and I don't know what this syntax is?
I have a search function, that searches for youtube videos and display them on
I know I'm having a massive derp moment here and this is probably quite

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.