我是 ruby on rails 的新手.. 我遇到 gsub 问题.. 我每次去我的商店页面列表时都会显示“未定义的方法 `gsub' for nil:NilClass”..
这是我的代码:
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
提前致谢