- Read Tutorial
- Watch Guide Video
Our application is almost done, so in this section, we're going to deploy it to Heroku.
The first step is to create a project in Heroku. Remember, it has to be unique, so you won't be able to use the same name that I use. The command to create a project is,
heroku create wlp-overtime
This command will create a URL for you, like this:
One good thing about Heroku is it gives us a direct communication channel where we can push files and fetch them when needed.
If you type the command,
git remote -v
You can find a set of URLs that allow you to push and fetch files.
Next, we'll have to push the entire project, and the command for that is:
git push heroku master
Essentially, this command will not only push all the files, but will also compress and compile it for us. So, you'll have all the metadata and gem files ready.
Next we will migrate and seed the database, and the command for that is:
heroku run rake db:setup
This will migrate the database and run the seeds file for us, so all our sample data will be available online.
We have an error now!
This is because the confirmed
method for audit log is not available until some other parts of the application run. The update_audit_log
method throws an error. To fix this, let's change the order of precedence in our seeds.rb
file. Move the audit_log
creation before posts.
# db/seeds.rb AuditLog.create!(user_id: @user.id, status: 0, start_date: (Date.today - 6.days)) AuditLog.create!(user_id: @user.id, status: 0, start_date: (Date.today - 13.days)) AuditLog.create!(user_id: @user.id, status: 0, start_date: (Date.today - 20.days)) puts "3 audit logs have been created" 100.times do |post| Post.create!(date: Date.today, rationale: "#{post} rationale content Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", user_id: @user.id, overtime_request: 2.5) end puts "100 Posts have been created"
Go through the process of committing these changes and push them to GitHub and then to Heroku. After the code has been pushed, run the command:
heroku run rake db:setup
Next, restart heroku with the command heroku restart
Let's see what it looks like on the web. My URL is "https://wlp-overtime.herokuapp.com", and you can find yours right at the end of the deployment process.
You can navigate around the app to see if everything is working. One thing I notice is that the styles are not fully visible, and for this, we'll have to add the rails 12
gem. So, go to your Gemfile
and add:
# Gemfile gem 'rails_12factor'
Essentially, this gem works with heroku, especially in the connection area between heroku and rails.
Now, type the command bundle
, and push it up to heroku. In the meantime, you can go through the documentation of rails_12factor
to get an idea of what it does.
The admin's dashboard still isn't showing the correct styles, and so we'll fix that in the next guide.