From 0aace2986a9a7a6d4c84a9ba6819d3df7821e267 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 14 Oct 2023 10:15:24 -0400 Subject: Blogs have an author now --- app/controllers/admin/blogs_controller.rb | 1 + app/mailers/comment_mailer.rb | 6 ++---- app/models/blog.rb | 2 ++ app/models/user.rb | 2 ++ app/views/blogs/_blog.html.haml | 4 ++-- 5 files changed, 9 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index 8e288a8..f0ce519 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb @@ -25,6 +25,7 @@ class Admin::BlogsController < Admin::AdminController def create @blog = Blog.new(blog_params) + @blog.user = current_user if @blog.save flash.notice = "Blog created successfully!" diff --git a/app/mailers/comment_mailer.rb b/app/mailers/comment_mailer.rb index e72b17d..aeed1b0 100644 --- a/app/mailers/comment_mailer.rb +++ b/app/mailers/comment_mailer.rb @@ -1,13 +1,11 @@ class CommentMailer < ApplicationMailer def new_comment_email @comment = params[:comment] - @admin = User.first # this is weird - mail(to: @admin.email, subject: "[Four Island] Comment on #{@comment.blog.title}") + mail(to: @comment.blog.user.email, subject: "[Four Island] Comment on #{@comment.blog.title}") end def new_pending_comment_email @comment = params[:comment] - @admin = User.first # this is weird - mail(to: @admin.email, subject: "[Four Island] Pending comment on #{@comment.blog.title}") + mail(to: @comment.blog.user.email, subject: "[Four Island] Pending comment on #{@comment.blog.title}") end end diff --git a/app/models/blog.rb b/app/models/blog.rb index e640466..e43990e 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -4,10 +4,12 @@ class Blog < ApplicationRecord acts_as_taggable has_many :comments + belongs_to :user validates :title, presence: true validates :body, presence: true, if: :published validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published + validates :user, presence: true before_validation :set_draft_title before_save :set_published_at diff --git a/app/models/user.rb b/app/models/user.rb index 555729a..f9f68fa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,4 +5,6 @@ class User < ApplicationRecord :recoverable, :rememberable, :trackable, :validatable has_secure_token :pokeviewer_token + + has_many :blogs end diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index 5467683..ec61bb5 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml @@ -5,7 +5,7 @@ %span.post-day= blog.visible_date.day .blog-title %h2= link_to_unless_current blog.title, blog - .post-author Hatkirby + .post-author= blog.user.login.capitalize %ul.post-tag-3 - blog.tags.each do |tag| %li= link_to tag, tag_url(tag.name) @@ -16,6 +16,6 @@ - else = markdown(blog.body) %cite.bubble - %strong Hatkirby + %strong= blog.user.login.capitalize on = blog.visible_date.strftime("%B #{blog.visible_date.day.ordinalize}, %Y at %-I:%M:%S%P") -- cgit 1.4.1