Search code examples
ruby-on-railsransack

Ransack search not working in rails model but working fine in rails console


I have a problem with Ransack. Here is my Search Form

= search_form_for @query, :url => search_products_path, :html => { :method => :get } do |f|
    %dl.left
      %dl.left
        %dt= f.label :sku, t('shoppe.orders.sku')
        %dd= f.text_field :with_sku
      %dl.right
        %dt= f.label :name, t('shoppe.products.name')
        %dd= f.text_field :with_translated_name

and my model code for searching is

def self.with_sku(sku_string)
      sku_string = sku_string.squish
      where("LOWER(shoppe_products.sku) LIKE ?" , "%#{sku_string}%".downcase)
end

So. Problem is SKU search is not working when a number field is entered and converted to string but it is working fine when this is done in rails console. Any help would be loved :)


Solution

  • It was actually a problem with some of my associations. I updated them and it is working fine.