diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-14 10:15:24 -0400 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-14 10:15:24 -0400 |
| commit | 0aace2986a9a7a6d4c84a9ba6819d3df7821e267 (patch) | |
| tree | 450acd91cbd522d47577233ca28725ede6697bb2 | |
| parent | 07ac5db98c8884e0de81fc6c0ab873854a852ca5 (diff) | |
| download | thoughts-0aace2986a9a7a6d4c84a9ba6819d3df7821e267.tar.gz thoughts-0aace2986a9a7a6d4c84a9ba6819d3df7821e267.tar.bz2 thoughts-0aace2986a9a7a6d4c84a9ba6819d3df7821e267.zip | |
Blogs have an author now
| -rw-r--r-- | app/controllers/admin/blogs_controller.rb | 1 | ||||
| -rw-r--r-- | app/mailers/comment_mailer.rb | 6 | ||||
| -rw-r--r-- | app/models/blog.rb | 2 | ||||
| -rw-r--r-- | app/models/user.rb | 2 | ||||
| -rw-r--r-- | app/views/blogs/_blog.html.haml | 4 | ||||
| -rw-r--r-- | db/migrate/20231014140431_add_user_to_blog.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 5 |
7 files changed, 18 insertions, 7 deletions
| 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 | |||
| 25 | 25 | ||
| 26 | def create | 26 | def create |
| 27 | @blog = Blog.new(blog_params) | 27 | @blog = Blog.new(blog_params) |
| 28 | @blog.user = current_user | ||
| 28 | 29 | ||
| 29 | if @blog.save | 30 | if @blog.save |
| 30 | flash.notice = "Blog created successfully!" | 31 | 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 @@ | |||
| 1 | class CommentMailer < ApplicationMailer | 1 | class CommentMailer < ApplicationMailer |
| 2 | def new_comment_email | 2 | def new_comment_email |
| 3 | @comment = params[:comment] | 3 | @comment = params[:comment] |
| 4 | @admin = User.first # this is weird | 4 | mail(to: @comment.blog.user.email, subject: "[Four Island] Comment on #{@comment.blog.title}") |
| 5 | mail(to: @admin.email, subject: "[Four Island] Comment on #{@comment.blog.title}") | ||
| 6 | end | 5 | end |
| 7 | 6 | ||
| 8 | def new_pending_comment_email | 7 | def new_pending_comment_email |
| 9 | @comment = params[:comment] | 8 | @comment = params[:comment] |
| 10 | @admin = User.first # this is weird | 9 | mail(to: @comment.blog.user.email, subject: "[Four Island] Pending comment on #{@comment.blog.title}") |
| 11 | mail(to: @admin.email, subject: "[Four Island] Pending comment on #{@comment.blog.title}") | ||
| 12 | end | 10 | end |
| 13 | end | 11 | 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 | |||
| 4 | acts_as_taggable | 4 | acts_as_taggable |
| 5 | 5 | ||
| 6 | has_many :comments | 6 | has_many :comments |
| 7 | belongs_to :user | ||
| 7 | 8 | ||
| 8 | validates :title, presence: true | 9 | validates :title, presence: true |
| 9 | validates :body, presence: true, if: :published | 10 | validates :body, presence: true, if: :published |
| 10 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published | 11 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published |
| 12 | validates :user, presence: true | ||
| 11 | 13 | ||
| 12 | before_validation :set_draft_title | 14 | before_validation :set_draft_title |
| 13 | before_save :set_published_at | 15 | 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 | |||
| 5 | :recoverable, :rememberable, :trackable, :validatable | 5 | :recoverable, :rememberable, :trackable, :validatable |
| 6 | 6 | ||
| 7 | has_secure_token :pokeviewer_token | 7 | has_secure_token :pokeviewer_token |
| 8 | |||
| 9 | has_many :blogs | ||
| 8 | end | 10 | 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 @@ | |||
| 5 | %span.post-day= blog.visible_date.day | 5 | %span.post-day= blog.visible_date.day |
| 6 | .blog-title | 6 | .blog-title |
| 7 | %h2= link_to_unless_current blog.title, blog | 7 | %h2= link_to_unless_current blog.title, blog |
| 8 | .post-author Hatkirby | 8 | .post-author= blog.user.login.capitalize |
| 9 | %ul.post-tag-3 | 9 | %ul.post-tag-3 |
| 10 | - blog.tags.each do |tag| | 10 | - blog.tags.each do |tag| |
| 11 | %li= link_to tag, tag_url(tag.name) | 11 | %li= link_to tag, tag_url(tag.name) |
| @@ -16,6 +16,6 @@ | |||
| 16 | - else | 16 | - else |
| 17 | = markdown(blog.body) | 17 | = markdown(blog.body) |
| 18 | %cite.bubble | 18 | %cite.bubble |
| 19 | %strong Hatkirby | 19 | %strong= blog.user.login.capitalize |
| 20 | on | 20 | on |
| 21 | = blog.visible_date.strftime("%B #{blog.visible_date.day.ordinalize}, %Y at %-I:%M:%S%P") | 21 | = blog.visible_date.strftime("%B #{blog.visible_date.day.ordinalize}, %Y at %-I:%M:%S%P") |
| diff --git a/db/migrate/20231014140431_add_user_to_blog.rb b/db/migrate/20231014140431_add_user_to_blog.rb new file mode 100644 index 0000000..74af555 --- /dev/null +++ b/db/migrate/20231014140431_add_user_to_blog.rb | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | class AddUserToBlog < ActiveRecord::Migration[7.0] | ||
| 2 | def change | ||
| 3 | add_reference :blogs, :user, foreign_key: true | ||
| 4 | end | ||
| 5 | end | ||
| diff --git a/db/schema.rb b/db/schema.rb index 2a9b1df..56fd9bb 100644 --- a/db/schema.rb +++ b/db/schema.rb | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | # | 10 | # |
| 11 | # It's strongly recommended that you check this file into your version control system. | 11 | # It's strongly recommended that you check this file into your version control system. |
| 12 | 12 | ||
| 13 | ActiveRecord::Schema[7.0].define(version: 2023_10_12_190529) do | 13 | ActiveRecord::Schema[7.0].define(version: 2023_10_14_140431) do |
| 14 | create_table "audits", force: :cascade do |t| | 14 | create_table "audits", force: :cascade do |t| |
| 15 | t.integer "auditable_id" | 15 | t.integer "auditable_id" |
| 16 | t.string "auditable_type" | 16 | t.string "auditable_type" |
| @@ -41,6 +41,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_12_190529) do | |||
| 41 | t.datetime "updated_at", precision: nil, null: false | 41 | t.datetime "updated_at", precision: nil, null: false |
| 42 | t.boolean "published", default: false, null: false | 42 | t.boolean "published", default: false, null: false |
| 43 | t.datetime "published_at", precision: nil | 43 | t.datetime "published_at", precision: nil |
| 44 | t.integer "user_id" | ||
| 45 | t.index ["user_id"], name: "index_blogs_on_user_id" | ||
| 44 | end | 46 | end |
| 45 | 47 | ||
| 46 | create_table "ckeditor_assets", force: :cascade do |t| | 48 | create_table "ckeditor_assets", force: :cascade do |t| |
| @@ -358,6 +360,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_12_190529) do | |||
| 358 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true | 360 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true |
| 359 | end | 361 | end |
| 360 | 362 | ||
| 363 | add_foreign_key "blogs", "users" | ||
| 361 | add_foreign_key "comments", "blogs" | 364 | add_foreign_key "comments", "blogs" |
| 362 | add_foreign_key "pokeviewer_items", "pokeviewer_moves", column: "move_id" | 365 | add_foreign_key "pokeviewer_items", "pokeviewer_moves", column: "move_id" |
| 363 | add_foreign_key "pokeviewer_pokedex_entries", "pokeviewer_species", column: "species_id" | 366 | add_foreign_key "pokeviewer_pokedex_entries", "pokeviewer_species", column: "species_id" |
