This commit is contained in:
2018-11-11 10:12:43 -06:00
parent 8a7b3d8ae0
commit 869a9fc048
16 changed files with 412 additions and 13 deletions

30
app/models/blog.rb Normal file
View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: blogs
#
# id :integer not null, primary key
# article :text not null
# published_date :string default(""), not null
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer
#
# Indexes
#
# index_blogs_on_user_id (user_id)
#
class Blog < ApplicationRecord
belongs_to :author, class_name: "User", foreign_key: :user_id, inverse_of: :blogs
scope :published, -> { where("published_date <= ?", Time.zone.now) }
def published?
return false if published_date.empty?
Time.zone.parse(published_date) <= Time.zone.now
end
end

View File

@ -20,6 +20,8 @@
class User < ApplicationRecord
has_secure_password
has_many :blogs, dependent: :destroy
validates :display_name, presence: true
validates :email, presence: true, email_format: true, uniqueness: true
validates :password_confirmation, presence: true, if: ->(m) { m.password.present? }