繁体   English   中英

Rails 模型中的强参数

[英]Strong Params in Rails model

我有一个模型Peoples::Friend和我的friend.rb是:

attr_accessible :name, :age

由于批量分配漏洞,我删除了这一行。 我有这个控制器peoples_controller.rb

friend = Peoples::Friend.update_attributes(:name => "test", :age => 23)

我删除了上面的行并添加了以下几行:

friend = Peoples::Friend.update_attributes(peoples_friend_params)

并添加了这个功能:

def peoples_friend_params
    params.require(:peoples_friend).permit(:name, :age)
end

现在,当我运行 API 时,它显示ActionController::ParameterMissing (param is missing or the value is empty: peoples_friend)

怎么了?

问题是我调用这个 API 的页面发送了params而不是peoples_friend 所以,我这样做了:

params.permit(:name, :age)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM