Can I run my heroku app in Test/Development environment - ruby-on-rails

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.

Related

Rails/Heroku - calling ruby class method

I have a method in a class (Scraper.rb) that saves some data to the app's database. On my dev environment I just call it through the command line. How can I call it on an app that's hosted on Heroku?
If you want to run the method from heroku console as your dev env. you can run command
heroku run console
or
heroku run rails c
This would normally do the trick in my app:
heroku run rails runner Scrapper.rb -e production
Obviously my app is in production in heroku so you apply the environment you want.

run rails applicaton after capistrano deployment

Deploying rails app throw Capistrano first time: I deployed my rails app on another machine (server)
File structure for rails app ## this is my server
akshay#akshay:/var/www/model_demo$ ls
current releases repo revisions.log shared
cap -T ## showing a lots of rake task
like
cap deploy:migrate # Runs rake db:migrate if migrations are set
If I run this task it is not working saying
Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.
But when I run
cap production deploy # It works
Among all the listed task only cap production deploy
1: what exactly going on under the hood?
2: How might i run rake task which is provided by cap?
Any help would be appreciated !!!
Capistrano recepies are meant to run on local system.
Run it locally.
I catch my mistake. And as I followed Railscasts Capistrano screencasts, stackoverflow Capistrano Tags and deploying-rails-apps-to-a-vps-with-capistrano-v3.
As all cap tasks run locally.
cap production deploy:migrate # Worked for me
Thanks to #maxd !!!

How to force Rails 4 app into production mode in Nginx and Unicorn?

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.

rails 3.2 : can not run in production mode

There is a problem while running the application in production mode. I want to set as default to run it as production.
RAILS_ENV="production"
I added above line in application.rb but no luck.
Any idea how to make it possible. When I am uploading app to heroku it still runs in development, due to which I am not able to keep my databases separate.
The application.rb is not the best place to define environment variables. On Heroku, you can define RAILS_ENV with heroku config:add RAILS_ENV=production
Adding RAILS_ENV="production" to application.rb wont help. Read the Heroku documentation on getting started.

rails3 app ENV not being recognized as production

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.

Resources