Created
September 11, 2012 14:52
-
-
Save coreyhaines/3699356 to your computer and use it in GitHub Desktop.
Environment-based initializers in Rails - USE THEM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# what? why does your production code care what environment it is in? SILLY! | |
unless Rails.development? || Rails.test? | |
Slottd::CreatesReservationTimer.for(slot.id) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in code, no more environment check | |
Slottd::CreatesReservationTimer.for(slot.id) | |
# in config/development.rb | |
module Slottd | |
CreatesReservationTimer = Timers::Null | |
end | |
# in config/production.rb | |
module Slottd | |
CreatesReservationTimer = Timers::IronWorker | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
...and the 'old_school_use' has the advantage of having it all together, and making reading easier.
jb