This commit is contained in:
2025-08-11 06:10:19 +09:00
parent e6eeb88c14
commit 5239dc5967
4 changed files with 344 additions and 80 deletions
@@ -24,7 +24,12 @@ class ThreadPostsController < ApplicationController
def create
post = @thread.posts.new(post_params)
if post.save
render json: post, status: :created
render json: post.as_json.merge(image_url: (
if post.image.attached?
Rails.application.routes.url_helpers.rails_blob_url(post.image, only_path: true)
else
nil
end)), status: :created
else
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
end
@@ -37,6 +42,8 @@ class ThreadPostsController < ApplicationController
end
def post_params
params.require(:post).permit(:name, :body, :password)
params.permit(:name, :message, :password, :image).transform_values { |v|
v.presence
}
end
end