Reputation: 12399
Sometimes I need to insert a chunk of code into a Rails app to perform some kind of config. I seem to be missing something with regards to where this should go. Let's say, for example, awesome_print. I would like to eliminate it's color printing as I use it in logs and need this in production
and staging
only.
I've tried inserting it into environment.rb
, application.rb
, an initializer and such, yet none of these are appropriate. They each result in various errors.
Where would insert a config line such as:
if RAILS_ENV == 'production'
ap object, options = {:plain =>true}
if
Upvotes: 1
Views: 93
Reputation: 4807
Your code example doesn't work because object
is undefined. If you just want to set some defaults for the gem then you can create a file called awesome_print.rb
in the initializers directory.
if Rails.env.production? || Rails.env.staging?
AwesomePrint.defaults = {
:plain => true
}
end
See the 'Setting Custom Defaults' section on the github page: https://github.com/michaeldv/awesome_print
The linked section uses an .aprc
file in the user's home directory but it should work the same with an initializer.
Upvotes: 1