title: Search in Rails
body: <p>I have a table of "posts" with attributes that include <code>title</code> and <code>body</code>. </p>
  
  <p>posts_controller.rb:</p>
  
  <pre><code>class PostsController &lt; ApplicationController
    def index
      @posts = Post.search(params[:search], params[:id])
    end
  end
  </code></pre>
  
  <p>index.html.erb:</p>
  
  <pre><code> &lt;%= form_tag posts_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;
  
  &lt;hr /&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;th&gt;Title&lt;/th&gt;
      &lt;th&gt;Text&lt;/th&gt;
    &lt;/tr&gt;
   &lt;tr&gt;
    &lt;td&gt;&lt;hr&gt;&lt;/td&gt;
    &lt;td&gt;&lt;hr&gt;&lt;/td&gt;
  &lt;/tr&gt;
    &lt;% @posts.each do |post| %&gt;
  
      &lt;tr&gt;
        &lt;td&gt;&lt;%= post.title %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= post.text %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= link_to 'Show', :action =&gt; :show, :id =&gt; post.id %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= link_to 'Edit', :action =&gt; :edit, :id =&gt; post.id %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= link_to 'Destroy', { :action =&gt; :destroy, :id =&gt; post.id }, :method =&gt; :delete, :confirm =&gt; 'Are you sure?' %&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;hr&gt;&lt;/td&gt;
        &lt;td&gt;&lt;hr&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>and post.rb</p>
  
  <pre><code>def self.search(search, id)
   if search
     where(['name LIKE ?', "%#{search}%"])
   else
    scoped
   end
  end
  </code></pre>
  
  <p>When I submit the search params, I get an error message:</p>
  
  <pre><code>ActiveRecord::StatementInvalid in Posts#index 
  SQLite3::SQLException: no such column: name: SELECT "posts".* FROM "posts"  WHERE (name LIKE '%lorem%') 
  
  Extracted source (around line #23):
  
  23:   &lt;% @posts.each do |post| %&gt;
  </code></pre>
  
  <p>APD: I want to search by 'title'. </p>