简体   繁体   English

如何使用strong_parameters允许除user_id之外的所有属性?

[英]How to permit all attributes besides user_id using strong_parameters?

I would like to use something like that: 我想用这样的东西:

def answer_params
  params.require(:answer).permit!.without(:user_id)
end

这会有用吗?

params.require(:answer).permit!.except(:user_id)

I just want to put this out here, whitelisting is not DRY. 我只是想把它放在这里,白名单不是干的。 Imagine a JSON API for a document based entry that could have up to 100 (or more) attributes (key value pairs). 想象一下,基于文档的条目的JSON API可以包含多达100个(或更多)属性(键值对)。 Generally the only pieces you need concern with are attributes that can escalate privileges like user_id. 通常,您需要关注的唯一部分是可以升级user_id等权限的属性。

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

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