前提・実現したいこと
rails初心者です。
現在railsで質問投稿サイトを制作しています。
paramsを使いデータの受け渡しをする際にエラーが発生しました。
発生している問題・エラーメッセージ
エラーメッセージ AnswersTestTest#test_answer生成: ActiveRecord::RecordNotFound: Couldn't find Question without an ID app/controllers/answers_controller.rb:9:in `show' test/integration/answers_test_test.rb:15:in `block in <class:AnswersTestTest>' ### 該当のソースコード routes.rb get '/new_answer' => 'answers#show' resources :answers, only: [:create, :destroy] エラー出るアクションへのリンク <h3>質問内容</h3> <div class="question"> <p><%= @question.content %></p> </div> <%= link_to "回答する", new_answer_path(@question) %> answers_controller def show @user = current_user @question = Question.find(params[:id]) @answer = Answer.new(user_id: @user.id, question_id: @question.id) end answers_test_test.rb test "answer生成" do log_in_as(@user) get new_answer_path(@question) assert_template 'answers/show' assert_difference 'Answer.count', 1 do post answer_path, params: { answer: { content: "Lorem ipsum" } } end follow_redirect! assert_template 'home_pages/home' end ```ここに言語名を入力 ruby 2.6.3p62 Rails 5.1.6 sqlite3 1.3.13 開発環境 cloud9 ### 試したこと エラーの出るアクションへのリンクのあるページでは、questionオブジェクトは正常に動いています。(question.contentなども正しく出力されています) paramsの使い方に問題があるように思うのですが、自力では解決できませんでした。 よろしくお願いします。 ### 補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/13 05:53 編集
2019/10/13 05:47
2019/10/13 06:07
2019/10/13 06:16
2019/10/13 09:26