0

How can I detect that code is running outside the main rails app?

For example in a console, or in a rake task, or as part of a scheduler action, etc.

I understand that there are specific ways to do this for each case (i.e. check Rails::Console etc, but I am looking for a general way to this that will work for all cases.

To clarify a bit further. By "main rails app" I mean the "instance" of rails that is responding to http requests.

1
  • by detect you mean at runtime, retrospectively through logs, or something else? Commented Dec 29, 2016 at 14:45

1 Answer 1

1

To check if the server is active use:

Rails.const_defined? 'Server' 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks... works great (at least in Rails 5) do you know if this const is also defined in Rails 4? I assume so...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.