Search code examples
ruby-on-railsformssimple-formpatchupdate-attributes

Simple Form - filtering updated attributes in the log


Simple question about Simple Form:

I've an attribute in a user model for a token I'd like marked as [FILTERED] when passed over the network (as the password field does by default).

e.g.

I have:

Parameters: { "token"=>"WYXe3Z24JmUq", "email"=>"[email protected]", 
"password"=>"[FILTERED]"}}

I want:

Parameters: { "token"=>"[FILTERED]", "email"=>"[email protected]", 
"password"=>"[FILTERED]"}}

and an example form:

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

What option do I need to add to the field to achieve this? I'm certain there's an option, but I can't seem to find it anywhere.

Thanks in advance!

Steve.


Solution

  • in application.rb do the following:

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

    check this answer: How to filter parameters in rails?