Files
nairobi/app/models/site_customization/page.rb
Javi Martín 863b326142 Validate both the model and its translations
This way we guarantee there will be at least one translation for a model
and we keep compatibility with the rest of the application, which
ideally isn't aware of globalize.
2018-10-22 16:30:28 +02:00

23 lines
856 B
Ruby

class SiteCustomization::Page < ActiveRecord::Base
VALID_STATUSES = %w(draft published)
translates :title, touch: true
translates :subtitle, touch: true
translates :content, touch: true
include Globalizable
validates_translation :title, presence: true
validates :slug, presence: true,
uniqueness: { case_sensitive: false },
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) }
def url
"/#{slug}"
end
end