title: undefined method `gsub' for nil:NilClass
body: <p>I'm newvbie in ruby on rails.. I'm having problem with gsub.. I everytime I go to the list of my store page it says "undefined method `gsub' for nil:NilClass".. </p>
  
  <p>here is mycode :</p>
  
  <p></p>
  
  <pre><code>def self.search(search_val, page = 1)
      @search_val = search_val.gsub("'", "\\\\'")
      search_query = "store_id LIKE '%#{ @search_val }%' OR english_name LIKE '%#{ @search_val }%' OR chinese_name LIKE '%#{ @search_val }%'"
  select("jos_store.id, store_id, english_name, chinese_name, store_manager, delivery_area,year, week").joins("LEFT OUTER JOIN (SELECT id as store_replenishment, store, MAX(stock_movement) AS stock_movement FROM jos_store_replenishment GROUP BY store) AS replenishment ON replenishment.store = jos_store.id").joins("LEFT OUTER JOIN jos_stock_movement ON jos_stock_movement.id = replenishment.stock_movement").where(search_query).order("year DESC, week DESC").paginate :page =&gt; page, :per_page =&gt; 15  
    end
  </code></pre>
  
  <p></p>
  
  <p>thanks in advance</p>