Rails的4个强项:使它们有条件吗? [英] rails 4 strong params: make them conditional?
本文介绍了Rails的4个强项:使它们有条件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使strong_params有条件?
不需要编写2个单独的方法吗?如果某个条件为真时要在许可列表中添加某些属性,则
Is there a way to make strong_params conditional? Without the need to write 2 separate methods? In case where one would like to add certain attributes to the permit list when a certain condition is true
例如:
devise_parameter_sanitizer.for(:user) {|u| u.permit(:user,
:email,
:role,
)}
我在上面的示例中具有此:role属性。我只希望在Rails.env.development中允许使用此属性?
I have this :role attribute permitted in above example. I only want this attribute to be permitted when in Rails.env.development is there a way to do this?
推荐答案
Haven'找不到解决方案,所以我制作了2个方法并调用正确的param方法来处理记录。
Haven't found a solution, so I made 2 methods and call the correct param method to handle the records.
这篇关于Rails的4个强项:使它们有条件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文