venu
venu

Reputation: 813

Undefined method permit

I am practicing the posts in rails guide. In comments controller I write like this but it comes to error

class CommentsController < ApplicationController
  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(params[:comment].permit(:commenter, :body))
    redirect_to post_path(@post)
  end
end

Upvotes: 1

Views: 515

Answers (1)

Said Kaldybaev
Said Kaldybaev

Reputation: 9982

I'd recommend to follow up this guide

This should work:

class CommentsController < ApplicationController
  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end
end

Upvotes: 1

Related Questions