実現したいこと
commentテーブルに保存できるようにしたい
発生している問題
DB保存機能を実装中、遷移はできるのですがDBに保存されないという問題が発生しました。
コントローラー(該当箇所のみ) def create @comment = Comment.new(comment_params) if @comment.save redirect_to users_path else render :new, status: :unprocessable_entity end end private def comment_params params.require(:comment).permit(:birthdate, :strengths, :weaknesses, :image, :message).merge(user_id: current_user.id)ソースコード モデル class Comment < ApplicationRecord has_one_attached :image validates :image, presence: true validates :strengths, presence: true validates :weaknesses, presence: true validates :message, presence: true belongs_to :user end マイグレーションファイル class CreateComments < ActiveRecord::Migration[7.0] def change create_table :comments do |t| t.text :message, null: false t.date :birthdate, null: false t.text :strengths, null: false t.text :weaknesses, null: false t.references :user, null: false, foreign_key: true t.timestamps end end end ブラウザ上で遷移した際のログ(該当箇所のみ抜粋) Parameters: {"authenticity_token"=>"[FILTERED]", "user"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x00007f1970e14610 @tempfile=#<Tempfile:/tmp/RackMultipart20240124-34762-ggewrf.jpg>, @content_type="image/jpeg", @original_filename="staff1.jpg", @headers="Content-Disposition: form-data; name=\"user[image]\"; filename=\"staff1.jpg\"\r\nContent-Type: image/jpeg\r\n">, "strengths"=>"根性", "weaknesses"=>"器用貧乏", "birthdate(1i)"=>"1992", "birthdate(2i)"=>"9", "birthdate(3i)"=>"18", "message"=>"gannbare"}, "commit"=>"SEND"} User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1 Redirected to http://localhost:3000/
試したこと
・トラザクションの検証
・binding.pryを使用してのデバック (createアクションに記述したが反応しなかった)
・パラメーターの確認
・バリデーションの確認
・ログの確認
・ブラウザ上でのエラーの有無>
補足情報(FW/ツールのバージョンなど)
卒業制作で簡素なオリジナルアプリを作成しています。rails 7.0.0 を使用しています。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2024/01/23 23:31
2024/01/24 02:03
2024/01/24 02:35
2024/01/24 02:49
2024/01/24 05:02
2024/01/24 13:18