0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コメント機能実装エラー

Posted at

未解決ですがアウトプット
投稿に対するコメント機能実装中
下記エラー発生

147c5a62a1cd9a9552e448e34dffd606.png
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にとばしても特に治らず
というか普通にこんがらがってきた。。。

ルーティングのネストから見直してこよう

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?