2014-02-13 67 views
1

我正在練習rails guide中的帖子。在評論控制器我寫這樣,但它涉及到錯誤未定義的方法許可

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 

回答

1

我建議跟進這個guide

這應該工作:

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 
+1

感謝d解決方案及其工作 – venu

+1

@然後你接受它作爲答案 –