Only check that it is a Rails application once

Also avoid using try since is_a? is faster for this case.