【问题标题】:Simple Form - filtering updated attributes in the log简单表单 - 在日志中过滤更新的属性
【发布时间】:2015-07-08 22:36:56
【问题描述】:

关于简单形式的简单问题:

我在用户模型中有一个令牌属性,我希望在通过网络传递时将其标记为 [FILTERED](默认情况下,密码字段会这样做)。

例如

我有:

Parameters: { "token"=>"WYXe3Z24JmUq", "email"=>"test@testing.com", 
"password"=>"[FILTERED]"}}

我想要:

Parameters: { "token"=>"[FILTERED]", "email"=>"test@testing.com", 
"password"=>"[FILTERED]"}}

还有一个示例表格:

<%= simple_form_for @user do |f| %>
  <%= f.input :token %>
  <%= f.input :email %>
  <%= f.input :password %>
  <%= f.input :password_confirmation %>
  <%= f.button :submit %>
<% end %>

我需要在字段中添加什么选项来实现这一点?我确定有一个选项,但我似乎无法在任何地方找到它。

提前致谢!

史蒂夫。

【问题讨论】:

    标签: ruby-on-rails forms simple-form patch update-attributes


    【解决方案1】:

    在 application.rb 中执行以下操作:

    config.filter_parameters += [:password, :token]
    

    查看这个答案:How to filter parameters in rails?

    【讨论】:

      【解决方案2】:

      Rails 4

      附带说明,config.filter_paramters 已移至它自己的初始化程序。

      config/initializers/filter_paramter_logging.rb

      您需要添加以下代码行来过滤tokenpassword

      # Be sure to restart your server when you modify this file.
      
        # Configure sensitive parameters which will be filtered from the log file.
      
        Rails.application.config.filter_parameters += [:password, :token]
      

      【讨论】:

        猜你喜欢
        • 2020-07-12
        • 1970-01-01
        • 2016-05-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多