From 483182ceed0e27229cbc6a0cbfec21dfb79efa63 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 30 Jan 2019 18:03:58 +0100 Subject: [PATCH] Refactor scopes on site customization page model --- app/models/site_customization/page.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/site_customization/page.rb b/app/models/site_customization/page.rb index a4bb213ad..6dd8f8d2f 100644 --- a/app/models/site_customization/page.rb +++ b/app/models/site_customization/page.rb @@ -13,11 +13,12 @@ class SiteCustomization::Page < ActiveRecord::Base format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format } validates :status, presence: true, inclusion: { in: VALID_STATUSES } - scope :published, -> { where(status: "published").order("id DESC") } - scope :with_more_info_flag, -> { where(status: "published", - more_info_flag: true).order("id ASC") } - scope :with_same_locale, -> { joins(:translations) - .where("site_customization_page_translations.locale": I18n.locale) } + scope :published, -> { where(status: "published").sort_desc } + scope :sort_asc, -> { order("id ASC") } + scope :sort_desc, -> { order("id DESC") } + scope :with_more_info_flag, -> { where(status: "published", more_info_flag: true).sort_asc } + scope :with_same_locale, -> { joins(:translations).locale } + scope :locale, -> { where("site_customization_page_translations.locale": I18n.locale) } def url "/#{slug}"