Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter parameters by model in a Rails app

I'm filtering passwords in my Rails 3.1 app's config/application.rb file as usual with:

config.filter_parameters += [:password]

However, I'm got an email field in two different models, and I'd like to filter email from only one of those models. Is there a way to do this?

like image 960
GarlicFries Avatar asked Feb 02 '26 06:02

GarlicFries


1 Answers

I know this question is really old, but I got here before finding the solution elsewhere. So I'll post an answer in case it helps someone:

In Rails 7, you can do:

class MyModel < ApplicationRecord
  self.filter_attributes += [ :email ]
end

to filter attributes per model

like image 105
gumlym Avatar answered Feb 04 '26 19:02

gumlym



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!