title: Search using like query in Ruby on Rails
body: <p>I am a beginner in ROR development. I have navigation and I want search box on every page and when I enter some keyword, it should do like query across table's field. I tried using some online tutorials but could not do it.
  My table name : tutorials
  here is my search form on navigation bar</p>
  
  <pre><code>&lt;li&gt;&lt;%= link_to 'Login', :controller =&gt; 'access', :action =&gt; 'login'  %&gt;&lt;/li&gt;
  &lt;li&gt;&lt;%= link_to 'Sign Up', :controller =&gt; 'users', :action =&gt; 'new'  %&gt;&lt;/li&gt;
  &lt;li&gt;&lt;%= link_to 'Logout', :controller =&gt; 'access', :action =&gt; 'logout'  %&gt;&lt;/li&gt;
  &lt;div align="right"&gt;
  &lt;%= form_tag("/search", method: "get") do %&gt;
    &lt;%= label_tag(:q, "Search for:") %&gt;
    &lt;%= text_field_tag(:q) %&gt;
    &lt;%= submit_tag("Search") %&gt;
  &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is my controller</p>
  
  <pre><code>class SearchController &lt; ApplicationController 
  
    def show
      @tutorial = Tutorial.find(params[:q])
  
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @tutorial }
      end
    end
  end
  </code></pre>
  
  <p>Here is my model</p>
  
  <pre><code>class Search &lt; ActiveRecord::Base
    def @tutorial.search(search)
      if search
        find(:all, :conditions =&gt; ['tutorial_name LIKE ?', "%#{search}%"])
      else
        find(:all)
      end
    end
  end
  </code></pre>
  
  <p>I am not sure how to do this. Please help</p>