RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: impedance
yes, thanks, and if you want to use it with pagination, for me it works like this:
def self.search(search) if search where('label LIKE ?', "%#{search}%") else where('label LIKE ?', "%#{}%") end end
but later I refactor it to scope
scope :search, lambda { |search| where("label LIKE ?", "%#{search}%")}
Hello, also you can use such scope: scope :search, lambda { |search| where("label LIKE ?", "%#{search}%")}
as the result query you will have objects which can be paginated also, and it will not crash even if "search" will be nil.
yes, thanks, and if you want to use it with pagination, for me it works like this:
but later I refactor it to scope
Hello, also you can use such scope:
scope :search, lambda { |search| where("label LIKE ?", "%#{search}%")}
as the result query you will have objects which can be paginated also, and it will not crash even if "search" will be nil.