允许在DeviseTokenAuth强参数中传递数组 [英] Allowing to pass an array in DeviseTokenAuth strong params
本文介绍了允许在DeviseTokenAuth强参数中传递数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有强大的参数问题,在Devise令牌认证宝石中传递了一个数组 LINK
I am having issue with strong params, passing an array in Devise Token Auth gem LINK
# ERROR
Unpermitted parameters: options
配置允许的参数
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << [:username, options: []]
end
# also added in User.rb file
attr_accessor :options
我尝试了很多选项,但不允许我传递数组。
I have tried many options, but its not allowing me to pass a data in array.
有什么解决方案吗?
谢谢!
推荐答案
这里是一个帮助您设置参数的例子:
Here is the example that will help you to setup the parameters:
# You can put the params you want to permit in the empty array.
def configure_sign_up_params
devise_parameter_sanitizer.for(:sign_up).push(:first_name, :last_name, :arr_options)
end
在您的模型中:
class User
attr_accessor :arr_options
def initialize
self.arr_options = []
end
end
这篇关于允许在DeviseTokenAuth强参数中传递数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文