0

I am creating a blog using ruby on rails. I am following a tutorial that is using an older version on rails. I am trying to post comments about the blog post on the same page. whenever i hit the submit button i get this error message. ActiveModel::ForbiddenAttributesError

Extracted source (around line #44):

def create
@post = Post.find(params[:post_id])
@comment= @post.comments.new(params[:comment])

respond_to do |format|
  if @comment.save

Here is my code inside my controller

def create
  @post = Post.find(params[:post_id])
  @comment= @post.comments.build(params[:comment])

  respond_to do |format|
    if @comment.save
      format.html { redirect_to @post, notice: 'Comment was successfully created.' }
      format.json { render json: @post, status: :created, location: @comment }
    else
      format.html { render action: "new" }
      format.json { render json: @post.errors, status: :unprocessable_entity }
    end
  end

Thanks for the help

1
  • Can you show comment.rb file's line which says: attr_asseccible, also post the form code.
    – Surya
    Nov 24, 2014 at 5:25

1 Answer 1

1

I guess you are using Rails 4. If so, the needed parameters must be marked as required in controller.

You can refer http://stackoverflow.com/questions/17868427/rails-4-activemodelforbiddenattributeserror

Not the answer you're looking for? Browse other questions tagged or ask your own question.