Should the database.yml be configured when testing locally for Heroku with foreman? - ruby-on-rails

Can someone explain to me what they do when they initialise a rails app locally with foreman (part of Heroku toolbelt) (using postgreSQL), destined to run on Heroku?
I'm going by this guide: developing locally with foreman and what I don't understand is if we are expected to specify database username and passwords or if foreman is supposed to handle it as Heroku itself does?
This perplexes me a little as if we are supposed to modify the database.yml to hook it up to postgreSQL, then what is the point of using foreman instead of rails server?
If it does handle it, how does it handle it, and how would I configure my pg_hba.conf to respect it? Something like local all myuser trust?

Yes, database.yml needs to be configured with valid information for your development and test databases.
Foreman is only running what's in your Procfile, not ripping things out and plugging different things in like Heroku does.
So why do you want to use Foreman instead of rails server? Because it:
Runs all roles defined in your Procfile with one command
Automatically loads your .env
Will fail if any of your roles fail (so less scratching your head because some necessary backend service isn't running)

Related

How to run rails applications on digitalocean using "rails s" (make it a development environment)

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.

Connecting Rails to AWS MySQL database

I've recently created a rails app. I pushed the initial files onto github.
My problem is that I want to connect my rails app to AWS in order to use a MySQL database. I keep seeing tutorials on EC2 and Beanstalk, but I am not sure which one I should use. I have all the drivers needed for ruby through the gem installations.
I'm looking to figure out the main differences between Beanstalk and created a MySQL instance as well as what to put in my database.yml file in my rails app to connect to a database. Thank you in advance!
Just to give an idea, after you provision/create your instance on AWS (EC2 or wherever), you will then push your app's code to that remote server somewhere. You can do it manually via scripts, or you can use Capistrano for this. Once your app is deployed to the server, you need to connect to the server via SSH and manually edit the config/database.yml file to point to the staging/production MySQL database. (I'm generalizing, but I think you just need a step in the right direction.)

Ruby on rails : launch server with code reload

I'm using a server for testing my api. I use this command to launch the server :
rails s -p 3001 -e test -P 42342
I change the port to 3001, to not have a conflict with my dev server (on port 3000).
The thing is that when I change code, the server don't reload the code, I have to kill the server and relaunch.
Is there a parameters that I miss to launch my rails command ?
test is only designed for automated testing, with Rails running for a single test run. Since code should not be changing during a test case, it doesnt have many of the development mode features and is more like production in that regard. Its also intended to reset your database when running tests, which also doesnt seem to be your intention.
If you want (most) classes to auto-reload, always use the development environment.
If for some reason you need a different environment (more than just port, but different configs), you can look at creating a new environment, copying the configs for development (add new entries to config/environments/, config/database.yml, config/secrets.yml, and use as a group in the Gemfile.).

How do I deploy my rails app to Heroku using an existing SQL database?

I have an existing MySQL database and would like to build a Rails app on top of it. How do I deploy my app to Heroku but still use my existing database instead of the default PostgreSQL database?
EDIT
Rephrasing the question slightly (formerly, it was "Is it possible to deploy...").
Yes. You can configure your application any way you like including specifying a non-Heroku database in your config file, and including using the default Heroku paradigm of using environment variables for config but with manually set database URLs in the environment variables.
You can either continue hosting your MySQL database separately, or migrate your data to a MySQL database hosted within the Heroku platform, like ClearDB (provided as a Heroku add-on).
Yes, although Heroku recommends that you use PostgreSQL, it is possible to migrate MySQL to Postgres with their service. They have an article in their docs for just such a scenario: https://devcenter.heroku.com/articles/heroku-mysql
They recommend you first install the http://rubygems.org/gems/mysql2psql gem
If your needs are MySQL specific and you have to use heroku clearDB has and addon https://addons.heroku.com/cleardb that you can use with your heroku app.

Rails app won't connect to PostgreSQL

I'm coming from the PHP/MySQL world, trying to set up a Rails/PostgreSQL app. It doesn't seem to want to connect and I'm having a hard time pinning down the cause of the problem. Are there certain troubleshooting steps I can take to figure out what's going wrong?
Update: the problem is not with PostgreSQL. I can connect to PostgreSQL via the command line, remotely via an IDE, and via a PHP script. I just can't seem to connect to it through this Rails app.
First I'd start with the actual database.yml file to make sure i have all the right user and password information.
I'd also make sure i ran whatever it is you do to make postgres start it's server, so that connections can be established. (Whether you use a psql start or it starts when you start your dev env. So only you can answer that one).
Is the database created?
Can i connect through console? rails console shouldn't give an error.
Do you have the correct postgres gem installed and is that in your bundle file (or environment.rb file)?

Resources