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

Surya
  • 15,703
  • 3
  • 51
  • 74
Orion_Blue
  • 15
  • 6
  • Can you show comment.rb file's line which says: `attr_asseccible`, also post the form code. – Surya Nov 24 '14 at 05:25

1 Answers1

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

Kranthi
  • 1,377
  • 1
  • 17
  • 34