Skip to content
Snippets Groups Projects
Unverified Commit c1672fb3 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

slug validator

parent 0923d5c5
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,8 @@ class Communication::Website::Author < ApplicationRecord
class_name: 'Communication::Website::Post',
dependent: :nullify
validates :slug, uniqueness: { scope: :website_id }
scope :ordered, -> { order(:last_name, :first_name) }
def to_s
......
......@@ -59,6 +59,7 @@ class Communication::Website::Category < ApplicationRecord
validates :name, presence: true
validates :slug, uniqueness: { scope: :website_id }
scope :ordered, -> { order(:position) }
......
......@@ -63,6 +63,7 @@ class Communication::Website::Page < ApplicationRecord
dependent: :nullify
validates :title, presence: true
validates :path, uniqueness: { scope: :website_id }
before_validation :make_path
after_save :update_children_paths if :saved_change_to_path?
......
......@@ -49,11 +49,12 @@ class Communication::Website::Post < ApplicationRecord
foreign_key: 'communication_website_post_id',
association_foreign_key: 'communication_website_category_id'
validates :title, presence: true
validates :slug, uniqueness: { scope: :website_id }
scope :ordered, -> { order(published_at: :desc, created_at: :desc) }
scope :recent, -> { order(published_at: :desc).limit(5) }
validates :title, presence: true
def github_path_generated
"_posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html"
end
......
......@@ -2,8 +2,6 @@ module WithSlug
extend ActiveSupport::Concern
included do
validates :slug,
uniqueness: { scope: :university_id }
validates :slug,
format: { with: /\A[a-z0-9\-]+\z/, message: I18n.t('slug_error') }
end
......
......@@ -36,6 +36,8 @@ class Education::Teacher < ApplicationRecord
association_foreign_key: 'education_program_id'
has_many :websites, -> { distinct }, through: :programs
validates :slug, uniqueness: { scope: :university_id }
scope :ordered, -> { order(:last_name, :first_name) }
def to_s
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment