I need to run this Rails.logger.info "SMTP_ADDR: #{ENV["SMTP_ADDRESS"].inspect}" in stdout console on my VPS
I'm not sure how to access the stdout console
can someone please advise?
I'm not sure what you mean by stdout, but if you need run this on your VPS environment, rails console probably will help you.
For production environment, run it in the app directory:
RAILS_ENV=production bundle exec rails console
Omit or change rails_env variable for another environment.
Related
I was trying to run my test cases on heroku.
Fund many blogs/answers telling how to run staging/custom environment on heroku.But whenever I run heroku run rspec spec/ it returns you are running production environment(not exact error).
So my qustion is not how to run staging/custom evironment on heroku but when I login into heroku rails console, I should be able to see
Rails.env #=> test
Or staging or whatever.
Any help is appreciable.
In heroku dashboard, you should just set RAILS_ENV and RACK_ENV to test.
You can do that here:
After setting these variables, I was able to start the console in test environment.
I am running a Rails 4 app on a VPS with Ubuntu, NginX and Unicorn.
When I SSL into my server and update the app via git or run rake tasks on the database, my app always switches to development mode and I can't get it into production mode.
Typing RAILS_ENV=production seems to have no effect at all.
When I do
$ rails console
$ Rails.env
I get
--> development
all the time.
What must I do to force NginX into production mode?
Actually, I don't want Nginx to ever run in development mode.
How can this be achieved?
Thanks for any help.
Your application is probably running in production mode by default. What you're doing is engaging a shell, something using a different environment.
Normally on a production server you'd put this into your profile script:
# Add to ~/.bash_profile
export RAILS_ENV=production
That way when you power up rails c you will get the correct environment.
As a note, the only way this shell is engaging in the first place is that you have a development setting in your config/database.yml. That shouldn't be there, as the configuration for your production server should be production-only.
nginx doesn't run in development or production mode - your app does, via your unicorn configuration and/or the RAILS_ENV environment variable when you launch your unicorn instances.
You should be launching your unicorn instances with the RAILS_ENV variable prefixed to the command, eg:
RAILS_ENV=production bundle exec unicorn -c config/unicorn.rb -D
rails console launches a completely different instance which may be in an different environment - it is unrelated to your unicorn instances. If you want to launch a production console instance, then either invoke RAILS_ENV=production rails console or rails console production. Note that this has no bearing on the environment that your application runs in.
I have an issue with running the rails console at heroku (cedar-stack). Each of the following commands heroku run console, heroku run rails console, heroku run bundle exec rails console results in the following error-message:
Running bundle exec rails console attached to terminal... up, run.8155
Abort testing: Your Rails environment is running in production mode!
This error-message is a little bit confused. What kind of test tries heroku to start? I just want to fire up the console, which had worked fine 4 weeks ago.
For Cedar Stack and later:
heroku run rails console --app <app name>
Previous stacks could use this command:
heroku run console --app <app name>
If you have multiple environments (staging / production / etc) you need this command:
heroku run -a app-name console
If you only have a single environment and never setup staging or other environments you can just run:
heroku run console
https://github.com/nemrow/rails_app_cheatsheet/blob/master/heroku.rdoc
For some reason you need to explicitly define the console process in the Procfile:
# Procfile
web: script/rails server -p $PORT
console: script/rails console
This blog post has more details: http://platypus.belighted.com/blog/2013/01/21/ruby-2-rails-4-heroku/
I was with the same problem and I decided to do this and it worked
$ heroku run bash
$ cd bin
~/bin $ ruby rails console
You should just use heroku run console as others have answered.
Heroku only runs in one environment at a time, which is configured by the RAILS_ENV and RACK_ENV environments variables.
When you connect, the console will use the correct environment automatically.
I have just gone live with my first Rails site, but now I have a problem. When I run the project in development mode on my IDE I can run the console to something like:
User.first.name='whatever' to change a users name.
How do I accomplish the same task on a live site in production mode?
if you're running rails 3.0 or greater, you can also use
rails console production
production can of course be substituted with development or test (value is development by default)
Adding the option --sandbox makes it so that any changes you make to your database in the console will be rolled back after you exit
If this isn't working for you, you may need to try
bundle exec rails console production
If you are actually trying to run the rails console on your production server, try googling "run rails console [your cloud hosting provider]" e.g. "run rails console heroku"
As of Rails 6 you need to use
RAILS_ENV=production bundle exec rails c
or
RAILS_ENV=production rails c
depending on your setup
Pretty easy:
RAILS_ENV=production rails console
If you have already deployed your site to the server, you can also use:
bundle exec rails console production
...in the webroot of your rails app. That is if you haven't installed the rails package directly on the server yet or if you want to run console within the context of your web app.
Try below command.
rails c -e production
Note: This answer assumes you are using Heroku as your hosting service.
It depends on what hosting service you are using. For Heroku, you can go to your terminal and type in
heroku run rails console
This will load up the rails console for your production site and will allow you to create records for your live site.
You can also look into seeding a database but that is generally meant for testing. RailsCasts has some videos on the topic but they are a bit outdated.
With Rails 6.1.6 on AlmaLinux8, the below command worked for me.
bundle exec rails console -e production
today with rails 6 run in console RAILS_ENV=production rails console
I set up my rails app on my linode VPS, phusion passenger is installed and working, so is mysql (I know this cause my friend currently is running 2 production apps on it with the same set up). The VPS is running Ubuntu 10.10 and I'm using apache2 with passenger.
I SFTP'd the app to the server, bundle updated, set up my virtual host and specified RailsEnv to be production and paths are all accurate.
I then restarted the server (as root) with
apachectl -k restart
tried to rake db:migrate and it didn't do anything, so I figured it was because the environment didn't get changed, which is exactly what happend. If I go into the rails console and type Rails.env it gives me development.
I have no idea why, I did everything that should set it to production? Anyone know what I may have missed? Is there somewhere in the app where I'm supposed to change something to say production environment? I thought that only had to be done in rails 2.x
Thanks in advance for any and all help.
The RailsEnv setting is only for Passenger's use. It doesn't affect the commands you type in the shell.
Use
RAILS_ENV=production rake db:migrate
and
RAILS_ENV=production rails console
Or set the RAILS_ENV environment variable in your login shell to production so that you don't have to append RAILS_ENV=production to the commands you issue:
export RAILS_ENV=production
(exact command may vary depending on which shell you use; the above works in bash)
You were on the right track; all you need to do to actually run the app in production mode is set the RailsEnv as you did, assuming you are running the app using Passenger. However, to run the database migrations you need to tell Rails what environment to run within.
The rails console command defaults to the 'development' environment by default. The same goes for running database migrations.
To run the migrations on your production environment you need to run the command as such:
RAILS_ENV=production rake db:migrate
And to run the console in production mode, you need to run the console using the command:
rails console production
If you want this variable to be set automatically, put RAILS_ENV=productionat the end of your ~/.bashrc file. (This only works with a bash terminal)
Then open a new terminal, or restart your ssh connection.