コメント機能実装エラー
未解決ですがアウトプット
投稿に対するコメント機能実装中
下記エラー発生
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"
.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
response_controller.rb
class ResponsesController < ApplicationController
def create
@comment = Response.create(response_params)
redirect_to "/top_page/#{comment.top_page.id}"
end
private
def response_params
params.require(:respons).permit(:comment).merge(user_id: current_user.id, top_page_id: params[:top_page_id])
end
end
top_page_controller.rb
class TopPageController < ApplicationController
def index
@toppages = TopPage.all
end
def new
@toppage = TopPage.new
end
def create
TopPage.create(top_page_params)
redirect_to top_page_index_path
end
def show
@toppage = TopPage.find(params[:id])
@comment = Response.new
@comments = @toppage.responses.includes(:user)
end
private
def top_page_params
params.require(:top_page).permit(:contents,:name).merge(user_id: current_user.id)
end
end
urlの飛ばし先が間違っているきがするのですが、top_pageにとばしても特に治らず
というか普通にこんがらがってきた。。。
ルーティングのネストから見直してこよう
Author And Source
この問題について(コメント機能実装エラー), 我々は、より多くの情報をここで見つけました https://qiita.com/forest0720/items/55cda48e394c1ba4df3f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .