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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:01:13+00:00 2026-06-09T07:01:13+00:00

I am wondering how should i proceed with a rails form search like twitter

  • 0

I am wondering how should i proceed with a rails form search like twitter to search multiple models.

I have implemented a search model/controller which will search based on the textbox and will eventually have ajax. But i am just wondering how can i implement it in my header file. Rendering may do is job but not sure how to call the searches controller.

Thanks in advance. Followed this tutorial http://railscasts.com/episodes/111-advanced-search-form

  • 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-09T07:01:14+00:00Added an answer on June 9, 2026 at 7:01 am

    One approach would be to create a Search class. Create a form partial that has a query input that when submitted, is send to the Search class. Search will then come up with a collection of search results, which you then output to a separate view. Having a Search class allows you to keep additional capabilities to your search–additional models and ways to rank results.

    Here is an skeletal example…

    class Search
      attr_accessor :query
    
      def initialize(*args)
        self.query = args[0] && args[0][:query] ? args[0][:query] : nil
      end
    
      def elements
        query.nil? ? [] : query.downcase.split(/ /)
      end
    
      def class_a
        class_a_objects = []
        ...some code that finds the objects you are searching for...
        return class_a_objects.uniq
      end
    
      def class_b
        class_a_objects = []
        ...some code that finds the objects you are searching for...
        return issuers.uniq
      end
    
      def class_c
        ..
      end
    
      ....
    
      def results
        class_a_objects + class_b_objects + class_c_objects
      end
    
    end
    

    In your searching code for each class, use the ‘elements’ method to search through the individual query objects.

    For the form

    = form_tag("/search", :method => :get) do
      = text_field 'search', :query
      = submit_tag 'search'
    

    Routes.rb

    match '/search' => "search#query", :as => 'search'
    

    Then a Search controller with a ‘query’ action. In this controller, simply do

    class SearchController
       def query
         @results = Search.new(:query => params[:search][:query] ).results
       end
    end
    

    Add a view ‘search’ for this controller action, where you render your @results. Your results will be a collection of individual objects from different classes, so your view can handle each item separately, which can be handled with additional partials, based on the object class.

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

Sidebar

Related Questions

I was wondering how should I proceed to debug while working with frameworks. Like
I am wondering how should I be grouping my repositories? Like from the examples
I have a project with several models like students,workers,administrators.... Of course those get different
I' was wondering should my primary key look like this PRIMARY KEY (id, category_id,
I'm wondering if I should be using a Backbone.Collection called ExerciseList for my exercises
I'm wondering whether I should create extension methods that apply on the object level
I'm wondering if I should use OpenId for my website. My first exposure to
I am wondering how I should structure a FAQ to keep the semantic meaning
I'm wondering if I should change the software architecture of one of my projects.
I am wondering what rights should be given to sql server user for asp.net

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.