mysql - Rails - How to search through multiple tables -


i trying implement search feature go across multiple tables. right have searching functionality each of individual tables in database.

as example able search 'title' multiple tables correspond title. 2 tables in example 'acts' , 'attachments'.

right have:

acts:

controller

 def index    if params[:search]      @acts = act.search(params[:search]).order('title desc')    else      @acts = act.all.order('title desc')    end  end 

model

class act < activerecord::base    def self.search(query)     where("title ?", "%#{query}%")   end end 

attachments:

model:

class attachment < activerecord::base   def self.search(query)     where("title ?", "%#{query}%")   end end 

controller:

def index   if params[:search]     @attachments = attachment.search(params[:search]).order('title desc')   else     @attachments = attachment.all.order('title desc')   end end 

any appreciated. new ror , trying implement correct way.

thank you.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -