How do I tell if rails is running under a web server, as opposed to a script or irb?
For context: I'm tracking an ActiveRecord object, and I want to email alerts if the objects changes, but only if the changes came through the web interface.
I have the task of my application performing several startup checks prior to starting up specifically as a server. In my particular case I want to make sure that a special User
record exists in the database since API calls made to my application require this User
.
I use the following hack in one of the initializers responsible for startup checks:
if defined? Rails::Server
puts "Running as a server..."
# Perform checks here...
end
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