Can you configure rails to only run an initializer under certain environments? In my case I had to hack paperclip to work with Imagemagick on my dev box, so I have monkeypatched code I want only to apply to the development environ, not the production environment. That monkeypatch is saved as a file in config\initializers.
The guides.rubyonrails.org site does not indicate that one can do this. If I can't I suppose I just won't check this patch into my repo, but that would not be ideal.
When we generate a new Rails application we get three environments by default: development , test and production . There's nothing special about these particular environments, though, and there are very few places in the Rails source code that refer to them.
Rails comes packages with 3 types of environments. Each have its own server, database, and configuration. See Rails Guides: Configuration for more information on options available to you.
An initializer is any file of ruby code stored under /config/initializers in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded.
Use command ENV in rails console. That will return a hash of your environmental values you can access. Alternatively, you can access your environmental variables from your apps root path using the same command and the variables will be returned formatted.
You could put this in an after_initialize
block in config/environments/development.rb
, or just surround it with if Rails.env.development?
in the initializer you already have.
I think either of these would work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With