first commit

This commit is contained in:
Sabic
2024-08-07 16:43:33 +02:00
commit f3b67b0800
111 changed files with 1993 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
+8
View File
@@ -0,0 +1,8 @@
class Article < ApplicationRecord
include Visible
has_many :comments, dependent: :destroy
validates :title, presence: true
validates :body, presence: true, length: {minimum: 10}
end
+5
View File
@@ -0,0 +1,5 @@
class Comment < ApplicationRecord
include Visible
belongs_to :article
end
View File
+19
View File
@@ -0,0 +1,19 @@
module Visible
extend ActiveSupport::Concern
VALID_STATUSES = ['public', 'private', 'archived']
included do
validates :status, inclusion: { in: VALID_STATUSES }
end
class_methods do
def public_count
where(status: 'public').count
end
end
def archived?
status == 'archived'
end
end
+3
View File
@@ -0,0 +1,3 @@
class User < ApplicationRecord
has_secure_password
end