Refactor scopes on site customization page model

This commit is contained in:
decabeza
2019-01-30 18:03:58 +01:00
parent cdb66ce23c
commit 483182ceed

View File

@@ -13,11 +13,12 @@ class SiteCustomization::Page < ActiveRecord::Base
format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format } format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
validates :status, presence: true, inclusion: { in: VALID_STATUSES } validates :status, presence: true, inclusion: { in: VALID_STATUSES }
scope :published, -> { where(status: "published").order("id DESC") } scope :published, -> { where(status: "published").sort_desc }
scope :with_more_info_flag, -> { where(status: "published", scope :sort_asc, -> { order("id ASC") }
more_info_flag: true).order("id ASC") } scope :sort_desc, -> { order("id DESC") }
scope :with_same_locale, -> { joins(:translations) scope :with_more_info_flag, -> { where(status: "published", more_info_flag: true).sort_asc }
.where("site_customization_page_translations.locale": I18n.locale) } scope :with_same_locale, -> { joins(:translations).locale }
scope :locale, -> { where("site_customization_page_translations.locale": I18n.locale) }
def url def url
"/#{slug}" "/#{slug}"