Rails.application should be set inside before_configuration hook

Fixes #14620