Add summaries to blog posts
This commit is contained in:
parent
69ff225b03
commit
e3a01ae633
|
@ -52,6 +52,7 @@ class BlogPostsController < ApplicationController
|
||||||
params.require(:blog_post).permit(
|
params.require(:blog_post).permit(
|
||||||
:title,
|
:title,
|
||||||
:content,
|
:content,
|
||||||
|
:summary,
|
||||||
:published,
|
:published,
|
||||||
:slug,
|
:slug,
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,6 +9,7 @@ class BlogPost < ApplicationRecord
|
||||||
:published,
|
:published,
|
||||||
:slug,
|
:slug,
|
||||||
:content,
|
:content,
|
||||||
|
:summary,
|
||||||
presence: true
|
presence: true
|
||||||
|
|
||||||
validates :slug, uniqueness: true
|
validates :slug, uniqueness: true
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div id="blog_post_<%= blog_post.id %>" class="blog_post">
|
<div id="blog_post_<%= blog_post.id %>" class="blog_post">
|
||||||
<h2><%= blog_post.title %></h2>
|
<h2><%= link_to blog_post.title, blog_post %></h2>
|
||||||
<%= blog_post.content %>
|
<p><%= blog_post.summary %></p>
|
||||||
<div class="created_at">
|
<div class="created_at">
|
||||||
<%= link_to "Edit", edit_blog_post_path(blog_post) if blog_post.user == current_user %>
|
<%= link_to "Edit", edit_blog_post_path(blog_post) if blog_post.user == current_user %>
|
||||||
<%= link_to blog_post.created_at.strftime("%Y-%m-%d %H:%M"), blog_post %>
|
<%= link_to blog_post.created_at.strftime("%Y-%m-%d %H:%M"), blog_post %>
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
<%= f.rich_text_area :content %>
|
<%= f.rich_text_area :content %>
|
||||||
|
|
||||||
|
<%= f.label :summary %>
|
||||||
|
<%= f.text_area :summary %>
|
||||||
|
|
||||||
<%= f.label :slug %>
|
<%= f.label :slug %>
|
||||||
<%= f.text_field :slug %>
|
<%= f.text_field :slug %>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
<%= render @blog_post %>
|
<div id="@blog_post_<%= @blog_post.id %>" class="blog_post">
|
||||||
|
<h2><%= @blog_post.title %></h2>
|
||||||
|
<p><%= @blog_post.content %></p>
|
||||||
|
<div class="created_at">
|
||||||
|
<%= link_to "Edit", edit_blog_post_path(@blog_post) if @blog_post.user == current_user %>
|
||||||
|
<%= link_to @blog_post.created_at.strftime("%Y-%m-%d %H:%M"), @blog_post %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= t(".discuss_post_html") %>
|
<%= t(".discuss_post_html") %>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
class AddSummaryToBlogPost < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
add_column :blog_posts, :summary, :string, null: true
|
||||||
|
BlogPost.update_all(summary: "")
|
||||||
|
change_column_null :blog_posts, :summary, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2023_10_05_151621) do
|
ActiveRecord::Schema[7.1].define(version: 2023_10_06_070935) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_05_151621) do
|
||||||
t.string "slug", null: false
|
t.string "slug", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "summary", null: false
|
||||||
t.index ["user_id"], name: "index_blog_posts_on_user_id"
|
t.index ["user_id"], name: "index_blog_posts_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,11 @@ published:
|
||||||
user: trevor
|
user: trevor
|
||||||
published: true
|
published: true
|
||||||
slug: published
|
slug: published
|
||||||
|
summary: Published!
|
||||||
|
|
||||||
draft:
|
draft:
|
||||||
title: A draft post
|
title: A draft post
|
||||||
user: trevor
|
user: trevor
|
||||||
published: false
|
published: false
|
||||||
slug: draft
|
slug: draft
|
||||||
|
summary: Draft!
|
||||||
|
|
|
@ -32,4 +32,9 @@ class BlogPostTest < ActiveSupport::TestCase
|
||||||
@post.content = nil
|
@post.content = nil
|
||||||
assert_not @post.valid?
|
assert_not @post.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "must have summary" do
|
||||||
|
@post.summary = nil
|
||||||
|
assert_not @post.valid?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue