Deploy Rails App to Heroku(Part 1)
Note: This article do not focused on how to create rails app but how to deploy rails app to heroku. We will generate our functionality of rails app using scaffold.
1. Generate rails app
Step 1 -
Use rails new method to generate rails application
rails new deploy_to_heroku
It will generate all the necessary files for your application.
Now cd into your rails app(deploy_to_heroku).
Step 2 -
This app will be a bookmark app which we can use to save bookmarks we like. As discussed we will use scaffold to generate our bookmarks app functionality. Lets do that real quick.
rails g scaffold Bookmark title:string url:string description:text
It will generate these all files.
Basically above scaffold command is saying rails to generate all controller, models, views & necessary routes for our application along with required functionality.
Run migration to create bookmarks table in database.
Step 3 -
You can run rake routes to see the mapping between incoming request and corresponding controllers#action.
Prefix we can use to go to that particular page but we have to add _path to it like if you use bookmarks_path in your ruby code it will go to app/views/bookmarks/index.html.erb file generated in correspondence with index action inside bookmarks controllers. Similarly new_bookmark_path will go to app/views/bookmarks/new.html.erb generated in correspondence with new action inside bookmarks controllers & so on.
Step 4 -
Now you can start your rails server using
Go to browser of your choice using url
It will take you here
Yeah your rails application is working :)
If you want you can change the root of your application to something else instead of this page.
For this just add a root path in your config/routes.rb file
Now if you go to the previous url you’ll find this page
So this section is complete I have created basic rails app if you have any trouble you can ask me in the comments below :)
In the next section we will initialize our git repository locally & will connect it to github meanwhile you can create an account on the github if you don’t have