简体   繁体   English

当用户使用设计唱歌时如何传递附加参数? 即使它不是用户列

[英]How to pass an additional parameter when the user singing up using devise? even it is not User coulmn

I want to send additional values when the user signs up and do some logic before creating the record using devise and devise-JWT in Rails API, I used that https://rubydoc.info/github/heartcombo/devise/main/Devise/ParameterSanitizer to permit additional parameters我想在用户注册时发送其他值并在使用 Rails API 中的 devise 和 devise-JWT 创建记录之前执行一些逻辑,我使用了https://rubydoc.info/github/heartcombo/devise/main/Devise/ ParameterSanitizer允许附加参数

choice is not a column in the User table.选择不是用户表中的列。

application_controller应用程序控制器

  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    attributes = [:choice]
    devise_parameter_sanitizer.permit(:sign_up, keys: attributes)
    devise_parameter_sanitizer.permit(:account_update, keys: attributes)
  end


ActionDispatch::Http::Parameters::ParseError (Error occurred while parsing request parameters):

According to Devise documentation, you are able to generate custom Devise controllers, so you may put your own logic.根据设计文档,您可以生成自定义设计控制器,因此您可以放置​​自己的逻辑。

https://github.com/heartcombo/devise#getting-started https://github.com/heartcombo/devise#getting-started

In my case, I added an attribute named "current_client_aplication_id" to the params object for respective request.就我而言,我为相应的请求向 params 对象添加了一个名为“current_client_aplication_id”的属性。 For knowing how do it, I had to inspect the params objct just in that line, using byebug for debuging.为了知道怎么做,我不得不检查那一行中的 params 对象,使用 byebug 进行调试。

#application_controller
before_action do
   session[:current_client_application_id] = "1"
   params[request["controller"].singularize]["client_application_id"] = session[:current_client_application_id] if params[request["controller"].singularize]
end

In this way, "current_client application_id" is available in all requests.这样,“current_client application_id”在所有请求中都可用。

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

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