vendredi 16 octobre 2015

Rails Join Scopes

I have on my model these scopes and i would like to make on the view a select sort_by: sort_by

scope :recent, -> { order(published_at: :desc) }
scope :low_price, -> { order(price: :desc) }
scope :high_price, -> { order(price: :asc) }
scope :popular, select("product_id, count(product_id) as count").group(:product_id).order("count desc").limit(3)

Is that possible with scopes? thank's

Aucun commentaire:

Enregistrer un commentaire