Search code examples
ruby-on-railssecurityruby-on-rails-4readability

Shorten call to Rails.application.secrets for readability


I know this is a bit of a nitpick, but this has been staring me in the face all day as I'm trying to move over to using the new[ish] config/secrets.yml file. It's just making my code ugly. I'm aware that moving to something less standard could be a problem if it comes to someone trying to understand my project... but this project is pretty private and i'm the only one working on it.

It seems that it's an instance of ActiveSupport::OrderedOptions so I can't seem to alias it.

How could I alias something like SECRET to Rails.application.secrets so that I could call SECRET.some_key to get a return value?

I'm looking for a solution that:

  • Has minimal performance impacts
  • Has minimal to zero security impacts

Thanks a zillion!


Solution

  • Why not just assign Rails.application.secrets to SECRET or @secret somewhere?

    SECRET = Rails.application.secrets 
    

    works for me in the console; I can then access SECRET.secret_key_base etc.