title: multi-table, mult-filters postgresql search - rails
body: <p>After looking through several options including pg_search, I'm having difficulty locating a resource that can help me understand how to put together multi-table, multi-filter searches.  I have two models, profile and subject, both of which are related through a unique_id.  What I'd like to do, is have the user select from numerous filters, across many models, and return the results.  For example, I'd like the user to be able to search the <em>name</em> attribute from the profile model and the <em>grade</em> attribute from the subject model and return a list that falls within those search parameters.  I have no problems creating one search filter, but when I add more filters for different categories, the other search filters don't seem to be communicating with one another.  Below is some of my code.  Happy to add more code, just really don't know where to being with this.  Any help or direction you could provide would be greatly appreciated.</p>
  
  <p><strong>Profile DB</strong></p>
  
  <pre><code>class CreateProfiles &lt; ActiveRecord::Migration
    def change
      create_table :profiles do |t|
        t.integer :unique_id
        t.string :name
        t.integer :age
        t.string :sex
        t.references :user, index: true, foreign_key: true
  
        t.timestamps null: false
      end
    end
  end
  </code></pre>
  
  <p><strong>Subject DB</strong></p>
  
  <pre><code>class CreateSubjects &lt; ActiveRecord::Migration
    def change
      create_table :subjects do |t|
        t.integer :unique_id
        t.string :subject
        t.integer :grade
        t.references :user, index: true, foreign_key: true
  
        t.timestamps null: false
      end
    end
  end
  </code></pre>
  
  <p><strong>Profile Model</strong></p>
  
  <pre><code>class Profile &lt; ActiveRecord::Base
  
  include PgSearch
  
    belongs_to :user
  
      def self.import(file)
      CSV.foreach(file.path, headers: true) do |row|
      attributes = row.to_hash
      Profile.create! attributes
     end 
    end
  
  
  end
  </code></pre>
  
  <p><strong>Subject Model</strong></p>
  
  <pre><code>class Subject &lt; ActiveRecord::Base
  
        include PgSearch
  
        belongs_to :user
  
        def self.import(file)
          CSV.foreach(file.path, headers: true) do |row|
          attributes = row.to_hash
          Subject.create! attributes
         end 
        end
  
      end
  </code></pre>