Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `gsub' for nil:NilClass

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"..

here is mycode :

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 => page, :per_page => 15  
  end

thanks in advance

like image 920
Lian Avatar asked Jul 16 '12 05:07

Lian


1 Answers

A good practice is doing .to_s when you are using string methods.

like image 143
YaBoyQuy Avatar answered Sep 30 '22 21:09

YaBoyQuy