我有点迷失了我得到了Rails 4错误:ActiveModel :: ForbiddenAttributesError.我明白,这意味着我需要允许项目通过,我已经做了,但我必须缺少一些东西.
评论控制人:
class CommentsController < ApplicationController def create @post = Post.find(params[:post_id]) @comment = @post.comments.create!(params[:comment]) redirect_to @post end private # Never trust parameters from the scary internet,only allow the white list through. def comment_params params.require(:comment).permit(:post_id,:comment,:body) end end
创建注释迁移
class CreateComments < ActiveRecord::Migration def change create_table :comments do |t| t.references :post t.text :body t.timestamps end end def self.down drop_table :comments end end
谢谢!