How to deploy a Ruby on Rails application on Heroku?

Member

by cierra , in category: Ruby , a year ago

How to deploy a Ruby on Rails application on Heroku?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by darion_leffler , a year ago

@cierra 

Deploying a Ruby on Rails application on Heroku involves a few steps. Here's a brief guide on how to do it:

  1. Create a Heroku account if you don't have one already.
  2. Install the Heroku CLI (Command Line Interface) on your local machine.
  3. Create a new Rails application using the rails new command.
  4. Set up your application to use a database. Heroku provides a managed PostgreSQL database, so you can add the pg gem to your Gemfile and configure your database.yml file to use it.
  5. Initialize a Git repository in your application's root directory using the git init command.
  6. Create a new Heroku application using the heroku create command.
  7. Push your application to the Heroku remote repository using the git push heroku master command.
  8. Run any necessary database migrations using the heroku run rails db:migrate command.
  9. Open your Heroku application using the heroku open command.


That's it! Your Rails application should now be deployed and running on Heroku.

Member

by mortimer , 3 months ago

@cierra 

Here's a more detailed step-by-step guide:

  1. Sign up for a Heroku account: If you don't already have one, go to Heroku's website (https://www.heroku.com/) and sign up for a free account.
  2. Install the Heroku CLI: Download and install the Heroku CLI for your operating system. You can find installation instructions on the Heroku Dev Center (https://devcenter.heroku.com/articles/heroku-cli).
  3. Create a new Rails application: In your terminal or command prompt, navigate to the directory where you want to create your Rails application and run the following command: rails new myapp Replace "myapp" with the name of your application.
  4. Configure your application's database: By default, Rails uses SQLite for development. However, Heroku recommends using PostgreSQL for production. Open your application's Gemfile and add the following line: gem 'pg' Save the file and run bundle install to install the PostgreSQL gem. Next, update your config/database.yml file to use the PostgreSQL database. Here's an example configuration for development: development: adapter: postgresql encoding: unicode database: myapp_development pool: 5 username: myapp password: Repeat the same configuration for test and production environments, but use different database names.
  5. Initialize Git repository: Run the following command in your application's root directory to initialize a new Git repository: git init
  6. Login to Heroku: Run the following command to log in to Heroku using the Heroku CLI: heroku login
  7. Create a new Heroku application: Run the following command to create a new Heroku application: heroku create This will create a new Heroku remote repository and add it as a Git remote.
  8. Deploy your application: Push your application to Heroku by running the following command: git push heroku master This will deploy your application to Heroku. You should see the build process in your terminal.
  9. Run database migrations: After your application is deployed, run any pending database migrations by running the following command: heroku run rails db:migrate This will execute the necessary database migrations on your Heroku application.
  10. Open your application: Finally, run the following command to open your application in your default web browser: heroku open This will open your application's URL in your web browser, allowing you to view your deployed Rails application on Heroku.


That's it! Your Ruby on Rails application is now deployed and running on Heroku.