diff --git a/app/models/communication/website/author.rb b/app/models/communication/website/author.rb index e316d74bf19f61ff662b30d732c52f5a9e7f58cc..a81414d3d43dd521f43c9f78d1275aa91afed90e 100644 --- a/app/models/communication/website/author.rb +++ b/app/models/communication/website/author.rb @@ -39,8 +39,6 @@ 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 diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 811c1d7e66f45d17490ad47298f1b7266afc48ab..5d662a5c3ed5e42ae298a44c315a541a4422e75e 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -59,7 +59,6 @@ class Communication::Website::Category < ApplicationRecord validates :name, presence: true - validates :slug, uniqueness: { scope: :website_id } scope :ordered, -> { order(:position) } diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 042b5bcf06cddbfdb42ec462539a912ebe37b5a3..5e7b1f45b56247773cfd420db7338f51bf9a7459 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -63,7 +63,6 @@ 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? diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 5896b97cd033b003d6dc831664f559e0b8a70984..51bbcec9b443d3d09c5be483adb9ddd3f48e2088 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -49,12 +49,11 @@ 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 diff --git a/app/models/concerns/with_slug.rb b/app/models/concerns/with_slug.rb index 793e8f090d6255472879482c391d82b55c88e77a..c13d07f016e818ec64cf5be2dfab675273d00ef0 100644 --- a/app/models/concerns/with_slug.rb +++ b/app/models/concerns/with_slug.rb @@ -2,6 +2,8 @@ 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 diff --git a/app/models/education/teacher.rb b/app/models/education/teacher.rb index 33e0abb228be0eb2397c3e5a86bdb2c8e8c584b9..970d4a4784f55e50c9d7de33a9a8901a3267ffd3 100644 --- a/app/models/education/teacher.rb +++ b/app/models/education/teacher.rb @@ -36,8 +36,6 @@ 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