Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring binstubs do not respect the --environment option. #729

Open
b-nik opened this issue Sep 30, 2024 · 0 comments
Open

Spring binstubs do not respect the --environment option. #729

b-nik opened this issue Sep 30, 2024 · 0 comments

Comments

@b-nik
Copy link

b-nik commented Sep 30, 2024

Up until recently, the binstubs generated by spring were using exception handling to decide whether to load Spring or not. This worked ok, and correctly didn't load Spring on production when rails was booting.

Recently ( here: 02649d9 ) a better approach was used, basically just checking the environment along with whether Spring is defined. However, since the --environment argument is checked after Rails boots, it's unfortunately not respected with this version.

Which means, commands like "bundle exec bin/rails console -e production" will produce a LoadError on production, since Spring is not in the bundler group for production, and since RAILS_ENV will be nil at the point the check is made.

I came across this issue by noticing my whenever created cronjobs not working, and that's exactly the reason why.

PS. To fix my case, I just added this not-super-fancy piece of code in my bin/spring file.

env_idx = ARGV.find_index{ |v| v == "-e" || v == "--environment" }
if env_idx
  env = ARGV[env_idx + 1]
  ENV["RAILS_ENV"] = env
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant