first commit
This commit is contained in:
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
primary_abstract_class
|
||||
end
|
8
app/models/article.rb
Normal file
8
app/models/article.rb
Normal 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
5
app/models/comment.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Comment < ApplicationRecord
|
||||
include Visible
|
||||
|
||||
belongs_to :article
|
||||
end
|
0
app/models/concerns/.keep
Normal file
0
app/models/concerns/.keep
Normal file
19
app/models/concerns/visible.rb
Normal file
19
app/models/concerns/visible.rb
Normal 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
3
app/models/user.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class User < ApplicationRecord
|
||||
has_secure_password
|
||||
end
|
Reference in New Issue
Block a user