解決はしたけどわからない。。。。
今回のエラーはコメントの投稿が反映されませんでした。
下記コード
top_page>show.html.haml
.main
= form_for @comment , url:{controller: 'responses', action: 'create'}do |f|
.main__consultation
.main__consultation__title
お悩み一覧
.main__consultation__text
= @toppage.contents
.main__comment
= f.text_area :comment, class: "main__comment__form"
= hidden_field_tag :top_page_id, value: @toppage.id
.main__comment__sent
= f.submit "投稿する"
.main__comment__text
<コメント一覧>
-if @comments
-@comments.each do |response|
.main__comment__main
.main__comment__main__name
= response.user.name
.main__comment__main__form
= response.comment
responses_controller.rb
class ResponsesController < ApplicationController
def create
response = Response.create(response_params)
redirect_to root_path
end
private
def response_params
params.require(:response).permit(:comment).merge(user_id: current_user.id, top_page_id: params[:top_page_id])
end
end
responsesにcreate!に変更してエラーを吐かせてみました。
するとこんな感じ。
バリデーションのエラーってことですよね?
モデルは確認して大丈夫そうだったので
binding.pryで覗いてみました。
値はしっかり入ってます。
ただこの
"top_page_id"=>"{:value=>13}"
valueに妙に違和感を感じたので、試しに外したところ。。。
投稿できました。。。。。。
謎です。valueも値を返すのでは?
そもそもvalueをつけるときとつけない時の差って???
有識者の方教えて頂けるとありがたいです。。。。