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

View File

@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end

8
app/models/article.rb Normal file
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
app/models/comment.rb Normal file
View File

@@ -0,0 +1,5 @@
class Comment < ApplicationRecord
include Visible
belongs_to :article
end

View File

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
app/models/user.rb Normal file
View File

@@ -0,0 +1,3 @@
class User < ApplicationRecord
has_secure_password
end