Files
grecia/app/models/site_customization/page.rb
María Checa 8894ec4f7c Pages form improvements
Added `locale` validation to model and improved its form select tag performance.
2017-07-02 21:28:13 +02:00

19 lines
695 B
Ruby

class SiteCustomization::Page < ActiveRecord::Base
VALID_STATUSES = %w(draft published)
validates :slug, presence: true,
uniqueness: { case_sensitive: false },
format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
validates :title, presence: true
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
validates :locale, presence: true
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, -> { where(locale: I18n.locale).order('id ASC') }
def url
"/#{slug}"
end
end