title: how to search through associations in rails 4
body: <p>I want to get all profiles whom subject names will match with search keyword. right now i am loading all profiles. i need to know how do i achieve it. Any help is much appreciated.</p>
  
  <p><strong>Profile.rb</strong></p>
  
  <pre><code>has_many :categorizations
  has_many :subjects, through: :categorizations
  </code></pre>
  
  <p><strong>Subject.rb</strong></p>
  
  <pre><code>has_many :categorizations
  has_many :profiles, through: :categorizations
  </code></pre>
  
  <p><strong>Categorization.rb</strong></p>
  
  <pre><code>belongs_to :profile
  belongs_to :subject
  </code></pre>
  
  <p><strong>views/search/index.html.erb</strong></p>
  
  <pre><code># search form
  &lt;%= form_tag search_index_path, :method =&gt; 'get' do %&gt;
    &lt;%= text_field_tag :search, params[:search] %&gt;
    &lt;%= submit_tag "search", :name =&gt; nil %&gt;
  &lt;% end %&gt;
  
  # search results
  &lt;% @profiles.each do |profile| %&gt;
    &lt;%= profile.name %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>search_controller.rb</strong></p>
  
  <pre><code>def index
    @profiles = Profile.with_translations('en').all
  end
  </code></pre>