Allowing to pass an array in DeviseTokenAuth strong params

北城以北 提交于 2019-12-24 00:54:44

问题


I am having an issue with strong params, passing an array in Devise Token Auth gem LINK

# ERROR
Unpermitted parameters: options

Configure Permitted Params

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.

Is there any solutions ?

Thank You!


回答1:


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

In your model:

class User
  attr_accessor :arr_options

  def initialize
    self.arr_options = []
  end
end


来源:https://stackoverflow.com/questions/36635111/allowing-to-pass-an-array-in-devisetokenauth-strong-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!