私はRubyonRailsの初心者です。gsubに問題があります。ストアページのリストにアクセスするたびに、「undefined method `gsub'for nil:NilClass」と表示されます。
これが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
前もって感謝します