diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index 79002f8..fb0d8b5 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -80,7 +80,7 @@ class PostsController < ApplicationController # TODO: URL が正規のものがチェック,不正ならエラー # TODO: URL は必須にする(タイトルは省略可). # TODO: サイトに応じて thumbnail_base 設定 - title = params[:title] + title = params[:title].presence url = params[:url] thumbnail = params[:thumbnail] tag_names = params[:tags].to_s.split(' ') @@ -121,7 +121,7 @@ class PostsController < ApplicationController return head :unauthorized unless current_user return head :forbidden unless current_user.member? - title = params[:title] + title = params[:title].presence tag_names = params[:tags].to_s.split(' ') original_created_from = params[:original_created_from] original_created_before = params[:original_created_before] diff --git a/backend/db/migrate/20260107034300_make_title_nullable_in_posts.rb b/backend/db/migrate/20260107034300_make_title_nullable_in_posts.rb new file mode 100644 index 0000000..80e6858 --- /dev/null +++ b/backend/db/migrate/20260107034300_make_title_nullable_in_posts.rb @@ -0,0 +1,28 @@ +class MakeTitleNullableInPosts < ActiveRecord::Migration[7.0] + def up + change_column_null :posts, :title, true + + execute <<~SQL + UPDATE + posts + SET + title = NULL + WHERE + title = '' + SQL + end + + def down + execute <<~SQL + UPDATE + posts + SET + title = '' + WHERE + title IS NULL + SQL + + change_column_null :posts, :title, false + end +end +