Follow Along as I Stumble on the Path to Learning RoR

Posts tagged “hash

Hiding Values from Appearing in Rails Logs

I had some fields that were sensitive, so I didn’t want the values appearing in the logs.  The solution was filtering them.  Doing that was easy.

In config/initializers/filter_parameter_logging.rb, and your fields, like so:

Rails.application.config.filter_parameters += [:password, :secret_field]

Now, when I look at the logs, I see this:

“user”=>{“password”=>”[FILTERED]”, “secret_field”=>”[FILTERED]”


ActiveAdmin: Turning Hashes/ActiveRecord Hashes to Field Values

After I installed ActiveAdmin gem, everything worked great except I had an issue where the dropdown menus were showing ActiveRecord hashes like this:

#<Category:0x698a648>

Instead of showing a name like the other fields.  It seems that the default is to show a field called “name” in the dropdown menus in ActiveAdmin, and if you don’t have such a field it shows the ActiveRecord instead.  Changing that was easy, after I found this StackOverflow question.

All you have to do is go into the model and add a method for to_s, like this:

def to_s
# field name you want to show in the drop down
end

for me, I put:

def to_s
id
end