下記のコードでNoMethodError in Posts#show ~undefined method "comments_path"~
のエラーが出てしまい進めません。
お助け願います。
↓Posts/show.html.erb
<div class="form-group"> <% form_for @comment do |f| %> <%= f.text_area :comment, placeholder: "コメントを入力", class: 'form-control' %> <%= f.submit '投稿', id: "submit", class: 'btn btn-primary btn-block' %> <% end %> ¥</div>
↓Comments_controller.rb
def created @post=Post.find(params[:post_id]) @comment = @post.comments.build(comment_params) @comment.user = current_user if @comment.save flash[:success] = 'コメントを投稿しました。' redirect_to post_path(@post) else flash.now[:danger] = 'コメントを投稿できませんでした。' render "posts/show" end end def comment_params params.require(:comment).permit(:comment, :image) end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/20 02:53