Configure Rails application per run and not per enviroment
I've got a Rails 3 application with some functionality I've written that I only wish to be active if I've specified it to be active for that application start alone.
I can't see how I would do this with initializers or the standard configuration strucuture as they are set per environment and and I don't want to have to go and change a configuration file everytime I want to switch my functionality on or off.
Ideally a command-line switch would work great...
rails server -run_my_functionality=true
... but I can't see anyway of making this work in Rails as it simply throws out my custom argument as unknown.
I'm usi开发者_Python百科ng JRuby to run my application, but I don't believe there is anything extra that is gives me to help with this.
Any way around this or anyone come up with a neater solution for per start configuration?
Cheers
Bear in mind that you can have as many environments as you want. Just add a config file to config/environments/my_env_name.rb
, add an entry under database.yml
, and you should be good to go: boot into your special environment for this special job.
Or, you could use an environment variable: DO_SOMETHING_SPECIAL=1 rails server
, then check its value with ENV['DO_SOMETHING_SPECIAL']
精彩评论