I have two different apps I'm working on, and have deployed both to heroku. I want to work locally and just view my app at localhost:3000, but how do I switch which app localhost:3000 displays? And how do I specify that each project gets committed/deployed to the right Heroku app?
You can start each app on a different port:
$ rails s -p 4000
Or use something like Pow
When you push to Heroku it will use the folder you're currently in (the remote repo is stored as part of the Git configuration).
Related
My issue is that I created a droplet to develop Rails apps in digitalocean .
I used the one-click rails droplet. And now I want to create more rails apps than the default rails app in this droplet.
The issue here is that it comes installed with nginx/unicorn .. And they're always on with path of default rails project in their config files.
Now let's assume I created another rails app(file) and I want to run it using "rails s" instead of default rails app that is created by the droplet. How can I do it?
Note: I don't want to change the file path in configs each time I decide to try another app
PS: I tried stopping the service of unicorn/nginx one at a time and both of them in the same time to use "rail s" to run the app .. But it didn't work .. Web pages were not loading
I know it might be a question of a rookie. But I'm kinda new to these stuff and I'd appreciate it if anyone could help me.
If you run it with rails s on the server, chances are it will be running with Puma, or if you're on an older version of Rails, Webrick. Unicorn is not involved in that case because Rails is using its own default web server. If you see that 'rails s' is not running in the right environment, it may be because RAILS_ENV is being set in your shell profile. You can override that by doing:
RAILS_ENV=development rails s
To launch your console.
That being said, rails s runs on localhost:3000 by default - and in the case you described it would be running on DigitalOcean's localhost - not yours. In order to get to it from your local machine, you would need to set up some sort of reverse proxy to allow connections to DO to get served from localhost. This is what nginx is doing for you - it's facilitating a reverse proxy.
If you want do use your DO server as a development machine for a second rails app you have, you're going to have to create that new rails app on the server, then create the reverse proxy settings in nginx to direct to it, then finally create the unicorn settings to serve it. This is an uncommon way of developing though. I recommend using your local machine to develop, and setting up Capistrano or some other deploy tool to deploy it to DO instead. You'd still need to add the settings in nginx/unicorn for the second app, but it will save you headache down the road.
I have a rails 5 app deployed on heroku. However, the chat features of the app is built using Node.js. While the rails app deploys fine on Heroku, the node server does not get started. How do I get the node part deployed? Does heroku allow both on a single dyno?
You can have multiple buildpacks. Here is the document that explains exactly your case https://devcenter.heroku.com/changelog-items/653
Simple question, I do all my work on my local at home computer and then I git push to my repo on github, and then on my Ubuntu Server I do a git pull to get the content, but this causes inconsistencies because it pulls in development mode which I always have to go in and change. Is there a way to make it so I can work in development mode but push it to the repo production mode? Thanks.
This isn't a git problem. Rails environments ('production', 'development', 'test') affect how the code runs, but the code isn't changed.
When you run rails server on your development machine, the application starts in development mode because that is the default for that command.
You probably aren't using the same command to host your site on WEBrick on your server, but rather using something like Phusion Passenger, which can (should) be configured to boot your application in Production mode.
If the environment is set correctly, the config/environments/#[RAILS_ENV}.rb file is correctly selected upon loading the app, and the correct database sources are selected from config/database.yml.
Rails apps default to development unless you set the RAILS_ENV variable to production. Git doesn't really factor in to this. On your production machine, you'll want to set RAILS_ENV.
Where to do this depends on your production deployment environment, and how your server is configured. Things like Passenger default to production mode, and configuring that depends on your server (Apache, nginx). If you're manually starting the server from the command line (via rails s thin or something along those lines), then you can configure it in your shell's startup file (.profile or something similar, depending on your shell). thin also optionally takes an environment argument like -e production.
If you provide more details on how your production environment works, you might get a more specific answer for where to set RAILS_ENV.
I need to switch my rails app from Heroku to my new host on Linode.
I need to address the following concerns and would appreciate some advice
1) How to migrate the data from Heroku to my new Linode host?
2) How to redirect the Heroku domain from myapp.herokuapp.com to my_new_host.com ?
I need to achieve the above as simultaneously as possible so that new data is not lost
Assuming you're running PostGres on your Linode host then you will simply need to backup your on Heroku and then restore it into Heroku (pgbackups). There are other options - You could use heroku db:pull to pull it down from Heroku into your local database and then transfer than to Linode. Another option would to be use the Heroku gem on your linode server to pull the data directly from the heroku app into the linode database.
You can only redirect on Heroku using code, so you would have to push up an app that does a redirect (rack_rewrite) to your new host.
You'll want to put your application on Heroku into maintenance mode on Heroku. Perform the data transfer via which ever mechanism you choose. Then deploy the 'redirect' code to the Heroku app and then turn maintenance mode off on Heroku. Visitors to the herokuapp.com address will then be redirected to the application running on the new URL wherever that may be.
I would like to test my rails app on my local machine and also have it functional on heroku. However, if I specify my IP address for the "Website" field on the facebook app settings, then my heroku breaks and vice versa. Is there any way to have them both work using the same API Key?
If not, how do I tell Omniauth to use one api key for the development environment and another for the production environment? Thanks!
Use a separate FB app for dev (local) and for production (Heroku).
Read the key out of the environment like:
ENV["FACEBOOK_APP_ID"]
ENV["FACEBOOK_SECRET"]
Then set the key/creds in your config on Heroku using heroku config:add.
Locally use foreman to run your app and set the dev key/creds in a .env file. http://blog.daviddollar.org/2011/05/06/introducing-foreman.html
Keep in mind that FB requires you to use SSL so you'll need to setup something locally that can handle SSL requests.
You will either have to create another development Facebook application for development, which is what I do, or you will have to create an entry in your /etc/hosts file that points the hostname of your Heroku app to you local machine.