How to search in rails from two models?

How doe I search in multiple models with the select option in Rails?

  • I am using sunspot gem and want to implement a search form like this I have two model articles and books this is my articles model class Article < ActiveRecord::Base      searchable do             text :title              text :content end this my books model class Book < ActiveRecord::Base       searchable do             text :title              text :description end i want to know how to implement the search form like this where user choose what they want to search books or articles

  • Answer:

    Did you look at Metasearch(or Ransack) under activerecord-hackery. It provides very nice ways to do searches across models. To throw in something more, Rayn Bates of rails casts has a small screencast about the usage of the same http://railscasts.com/episodes/370-ransack

Vineeth B Sathish at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.