2014-11-24 1 views
0

Ruby on Rails를 사용하여 블로그를 만들고 있습니다. 레일즈에서 이전 버전을 사용하는 자습서를 따르고 있습니다. 같은 페이지에서 블로그 게시물에 대한 의견을 게시하려고합니다. 제출 버튼을 누를 때마다이 오류 메시지가 나타납니다. ActiveModel :: ForbiddenAttributesError이전 버전의 루비를 사용하는 ActiveModel :: ForbiddenAttributesError?

는 는

추출 소스 (라인 # 44의 주위에) : 여기

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

respond_to do |format| 
    if @comment.save 

은 도움

+0

당신이 말한다 comment.rb 파일의 라인을 표시 할 수 있습니다 참조 할 수 있습니다. – Surya

답변

1

내가 당신을 추측에 대한

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 

덕분에 내 컨트롤러 안에 내 코드입니다 그렇다면 필요한 매개 변수가 컨트롤러에 필수로 표시되어야합니다. `attr_asseccible`, 또한 양식 코드를 게시 :

당신은 http://stackoverflow.com/questions/17868427/rails-4-activemodelforbiddenattributeserror

관련 문제