Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check rails environment?

How check rails environment on Ubuntu Server?

command: Rails.env => command not found command: rails.env => command not found

like image 823
Alexander Shlenchack Avatar asked Apr 27 '13 07:04

Alexander Shlenchack


People also ask

How do I see environment variables in rails?

Use command ENV in rails console. That will return a hash of your environmental values you can access. Alternatively, you can access your environmental variables from your apps root path using the same command and the variables will be returned formatted.

What environment does rails have by default?

When we generate a new Rails application we get three environments by default: development , test and production . There's nothing special about these particular environments, though, and there are very few places in the Rails source code that refer to them.

What is a rails environment?

Ruby on Rails Configuration Environments in Rails By default rails has 3 environments, development , production and test . By editing each file you are editing the configuration for that environment only. Rails also has a configuration file in config/application.

How is rails ENV set?

The ENV hash in your Rails application is set when your Rails application starts. Rails loads into ENV any environment variables stored in your computer and any other key-value pairs you add using Figaro gem.


5 Answers

One liner if you are in app root

rails r "puts Rails.env"

like image 133
Dino Reic Avatar answered Oct 17 '22 20:10

Dino Reic


It sounds like you tried to run Rails.env in a shell. That won't work because Rails.env is Ruby code, not a Unix shell command.

How are you deploying and starting your rails app on the server? The Rails environment is determined by whatever the value of the RAILS_ENV environment variable is when the server starts. You might have some configuration file somewhere that specifies it, or maybe you just start your server with a command of the form RAILS_ENV=production my_rails_server? I would need to know more details about exactly what commands you run to start the server in order to really answer this. Are you using unicorn, mongrel, Webrick, or something else?

like image 23
David Grayson Avatar answered Oct 17 '22 18:10

David Grayson


You can check complete details about your rails app. By typing this command "rake about". Will give you brief details about which version of ruby have you installed on your machine, rails version etc. For example -

About your application's environment

Rails version ------> 4.2.6

Ruby version ------> 2.3.1-p112 (x86_64-linux)

RubyGems version ----> 2.5.1

Rack version ----> 1.6.4

JavaScript Runtime -------> Node.js (V8)

Middleware ------> Rack::Sendfile, ActionDispatch::Static,

Application root ----> /data/www/testapp

Environment ------> development

Database adapter -----> mysql2

Database schema version -----> 0

like image 14
Rana Pratap Singh Avatar answered Oct 17 '22 18:10

Rana Pratap Singh


On your Rails Application directory type :

rake about

like image 12
Marcelo Campusano Avatar answered Oct 17 '22 20:10

Marcelo Campusano


rails r -e production 'p Rails.env'
production

rails r -e production 'p Rails.env.production?'
true

rails r 'p Rails.env'
development

rails r -e development 'p Rails.env.development?'
true

rails r -e test 'p Rails.env.test?'
true

PS If rails command not found try to use path bin/:

bin/rails r 'p Rails.env'
development

PS2 If use rvm, check installed ruby versions:

rvm list

ruby-2.2.0 [ x86_64 ]
ruby-2.2.4 [ x86_64 ]
ruby-2.6.2 [ x86_64 ]
ruby-2.7.0 [ x86_64 ]
ruby-2.7.1 [ x86_64 ]
=> ruby-2.7.2 [ x86_64 ]
* ruby-2.7.3 [ x86_64 ]
ruby-3.0.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Select to version:

rvm use ruby-3.0.0

Bundle install:

bundle
like image 5
shilovk Avatar answered Oct 17 '22 19:10

shilovk