user3437721
user3437721

Reputation: 2289

rails_env - where is code executed

If I run a rails console like this

Rails_env=uat

And run some code

user = User.find(1)
user.do something

Where the code executed, is it the code on the server, or my local code, which could be different?

Upvotes: 0

Views: 49

Answers (1)

max
max

Reputation: 102046

Its executed on the machine where the shell is running.

What the RAILS_ENV env var does is tell rails which config files to load. So if you use RAILS_ENV = production it will load /config/environments/production.rb and it will also use the production section in your database.yml.

It does not magically open a SSH connection and execute on your production server. Just think about it, how would that work? Rails has no idea where the production server lives and how to open a connection.

Warning!

However since it uses the production section in your database.yml it can change your production database if you are foolish enough to actually write the production server details in the file (Don't be a tool, use the DATABASE_URL env var).

Upvotes: 2

Related Questions