Web Programming TutorialsDeploying ROR on Heroku

Deploying ROR on Heroku

In this tutorial,we will try to create a simple blog on ROR and then deploy it on Heroku.

  • To get started with it follow the steps given below :

  1. Open the Git bash command prompt from : start->All Programs -> Rails Installer -> Git Bash
  2. 0

  3. The following window will get displayed.
  4. 1

  5. To create the new Project,type the command as
    rails new myrubyblog
  6. 2

  7. The following Dialog Box will appear.
  8. 3

  9. After you create your first application switch to its folder by giving following command :
    cd myrubyblog
  10. 4

  11. Now generate the controller and view for the project,so for that type command as :
    rails generate controller home index
  12. 5

  13. For testing your view is running on the server follow the steps given below:
    1. Now open the app/views/home/index.html.erb file in your text editor. Delete all the existing code in the file, and replace it with the following single line of code .
      <h1>MY RUBY BLOG</h1>
    2. Hence the window can be seen as follows :
    3. extra

    4. For setting the homepage for your application we have made the controller and view, we need to tell Rails when we want MY RUBY BLOG to show up. In our case, we want it to show up when we navigate to the root URL of our site, http://localhost:3000. At the moment, “Welcome Aboard” is occupying that spot.
    5. Next, you have to tell Rails where your actual home page is located.

      So open C:Sitesmyrubyblogconfigroutes.rb
    6. 6

    7. As we can see in the above window the highlighted part which is # root ‘welcome#index’
    8. So change it with root ‘home#index’ to show our view on the browser .
    9. 7

    10. If you now navigate to the http://localhost:3000/ you will see the following window
    11. 8

    12. Thus we have created our home page

  14. Now for configuring Our App to use the PostgreSQL follow the steps given below :
    1. Click on the start->All Programs->PostgreSQL 9.3->pgAdmin III.
      Click on pgAdmin III.
    2. 9

    3. After opening the pgAdmin III the following window will appear.
    4. 10

    5. In the above window go to the PostgreSQL 9.3 from the object browser and right click on it and then click on connect,following window will get displayed.
    6. 11

    7. Enter your PostgreSQL password and click on OK button.
    8. As we can see in the window given below:
      Right click on the data base.
      Then click on the New Database option
    9. 12

    10. After clicking on the New Database option following window Will Appear.
    11. 13

    12. Then type myrubyblog adjacent to the name as given below.Then click Ok button.
    13. 14

    14. This will create the database as we can see in the following window.
    15. 15

    16. Now Go to the file list of myrubyblog where it is saved on the system.
      You can see the file list as follows:
    17. 16

    18. Now navigate to myrubyblogconfig following window will appear.
    19. 17

    20. Open the database.yml file in your text editor.It will look like as shown below:
    21. 18

    22. Replace the following code :
      adapter: sqlite3
      database : db/development.sqlite3

      of development ,test and production module with

      adapter: postgresql
      database: myrubyblog
      username: postgres
      password: 1234
    23. 19

    24. Make sure to change with every module of development, test and production
    25. Now install the gems for PostgreSQL, type command as..
      gem install pg
    26. 20

    27. Now open the Gemfile from your myrubyblog folder through the text editor. The file can be found as below
    28. 21

    29. Open the Gemfile with the text editor
    30. 22

    31. Comment the highlighted code gem ‘sqlite3’ as shown in the image above and then write the new command as
      gem ‘pg’
    32. 23

  15. For installing the bundle into your application follow the steps given below :
    1. Open the git bash command prompt and enter the following command.
      bundle install


  16. Open the server and then keep running,to start the server type following command.
    rails s
  17. 25

  18. Now open the command prompt GIT bash and switch it to your myrubyblog application,by typing the following command..
  19. Now install Heroku gem in your application by inserting following command
    gem install heroku
  20. 26

  21. Install the bundle by typing the following command.
    bundle install
  22. 27

  23. To Check the Heroku version Type the following command.
    heroku version
  24. 28

  25. Now initialize the repository with the following GIT command
    git init
  26. 29

  27. Now add the repository by using the following command
    git add 
  28. 30

  29. Now commit the added part by typing the following command
    git commit  -m ‘any comment’
  30. 31

  31. Now login to you heroku account,type command as
    heroku login

    Then enter your heroku login name and password

  32. 32

  33. Now create the heroku app by typing the command
    heroku create
  34. 33

  35. This will create the app and give any random name to it as we can see in the window below we get the name as
  36. 34

  37. Now push our app to the server by typing the following command.
    git push heroku master
  38. 35

  39. After the app is successfully added to the server you can see the name of the app as follows
  40. 36

  41. Now open your heroku account through Url www.heroku.com and login into your account
  42. 37

  43. You will see our app is created as we can see floating-fjord-7103 is the name of our app.Make sure that the name of the app is generated randomly by the server.Now click on the settings as given in the picture below.
  44. 38

  45. You will see the following window
  46. 39

  47. Now scroll down to the window and find Domains as given below
  48. 40

  49. Now Click on the url Corresponding to the domain as given below
  50. 41

  51. You will see the following page.
  52. 42

  53. Thus we successfully deployed our first app on Heroku


Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article


More article

- Advertisement -