Search Multiple models in ruby on rails
ruby, ruby-on-rails
Solution
You can add ActiveRecord_Relations together, and it will give you a simple array
@results = Sundries.search(search_term) + Curry.search(search_term) + Starter.search(search_term)
In the view...
<% @results.each do |result| %>
<%= "#{result.title} part of our fine #{result.class.name} choices" %>
<% end %>
Problem
I am still a beginner in ruby on rails and I'm trying to create a simple search option for a website that I'm developing. I have number of models such as Sundries, Curry and Starter. My search works fine if I have one model but how do I search all models title or name? I have added following method to each of the models and tried to display results in home page. but no luck! ``` def self.search(search) where("LOWER(title) LIKE ?", "%#{search.downcase}%") #where("content LIKE ?", "%#{search}%") end ``` Can someone please help me figure this out with an example please? Thank you.