2014-09-29 123 views
0

我遇到强参数问题。强参数,不允许的参数

我的置换参数是:

def post_params 
    params.require(:post).permit(:content, :user_id, :topic_id).merge(:user_id => get_user.id) 
end 

传递的参数是:

{"utf8"=>"✓", 
"authenticity_token"=>"5+OEnLgihamJC37BSn4r/spoiRmccJzHhe6eaeC2Fuc=", 
"post"=>{"topid_id"=>"10", 
"content"=>"awfawfaw"}} 

而且创造功能:

def create 
    post = Post.new(post_params) 
    if post.valid? && post.save 
     redirect_to :controler => :topic, :action => :show, :topic => post.topic.id 
    end 
end 

enter image description here

这是控制台中的错误。我想知道为什么它不允许topic_id

+3

你有一个错字。你的日志显示'topid_id'而不是'topic_id'。 – mccannf 2014-09-29 21:36:50

+0

上帝保佑你的眼睛的细节;) – 2014-09-29 21:51:14

+0

我*真的*帮助我们帮助你,当你不使用屏幕抓取错误或文字。相反,复制并粘贴文本,确保其格式合理可读。 – 2014-09-29 22:52:20

回答

0

你有一个错字在你的允许PARAMS:

你所拥有的是:

def post_params 
    params.require(:post).permit(:content, :user_id, :topic_id).merge(:user_id => get_user.id) 
end 

,它应该是:

def post_params 
    params.require(:post).permit(:content, :user_id, :topid_id).merge(:user_id => get_user.id) 
end 

但是这取决于你的模型是什么名字属性在你的模型中。要么你必须改变表单中的错字形式,要么你必须改变其他地方。