When I tried to push Rails to Heroku after a while, I found that many things had changed, so here’s a note.
This assumes that the Heroku CLI is already installed.
It’s troublesome if it’s not up-to-date, so let’s update it first.
$ brew update
$ brew upgrade heroku
$ heroku --version
Previously, you had to enter your ID and password to log in, but now you can also log in through your browser.
$ heroku login
heroku: Press any key to open up the browser to login or q to exit:
$ heroku create
Edit config/environments/production.rb
# config/environments/production.rb
# Do not fallback to assets pipeline if a precompiled asset is missed.
[omitted]
config.assets.compile = true <= change false to true
ES6 parts cannot be compiled, so change to Uglifier.new(harmony: true)
. If you try to compile without changing this, you’ll get an error: Uglifier::Error: Unexpected token: punc ()). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true)
.
# config/environments/production.rb
[omitted]
## Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(harmony: true)
After this is done, compile. Always run asset precompilation before sending to Heroku when you’ve made changes to assets.
$ rails assets:precompile RAILS_ENV=production
$ git add -A
$ git commit -m "first heroku push"
$ git push heroku master
Heroku automatically creates a database, so rails db:create
is not necessary.
$ heroku run rails db:migrate RAILS_ENV=production
Once that’s done, access Heroku:
$ heroku open