Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if rails is running under a web server

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.

like image 917
rogueg Avatar asked Jul 23 '10 00:07

rogueg


1 Answers

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
like image 141
Alex Fortuna Avatar answered Sep 24 '22 16:09

Alex Fortuna