· 1 min read
Screencast: Squeel
Downloads in verschiedenen Formaten:
Resourcen:
terminal
[bash] rails g squeel:initializer rails c [/bash]
rails console
[ruby] Product.where{released_at < 3.months.ago} Product.where{released_at.lt 3.months.ago} Product.where{released_at.lt(3.months.ago) & price.gt(20)} Product.where{released_at.lt(3.months.ago) | price.gt(20)} [/ruby]
models/product.rb
[ruby] def self.search(query) where do (released_at <= Time.zone.now) & ((discontinued_at == nil) | (discontinued_at > Time.zone.now)) & (stock >= my{low_stock}) & (name =~ ”%#{query}%”) end end
def self.low_stock 2 end [/ruby]