-
Go to heroku and sign up
-
then go to: [https://devcenter.heroku.com/articles/getting-started-with-rails6] and install heroku cli tool
brew tap heroku/brew && brew install herokufor mac and for linuxsudo snap install --classic heroku👈 if this command does not work for ubuntu, scroll further down at the page and you will seecurl https://cli-assets.heroku.com/install-ubuntu.sh | shrun it, which we are running things from internet, which is an http request to install-ubuntu and we are piping it to 'sh'. You have to be careful when you do that, I trust heroku but, they could have been hacked, who knows. Note: follow the steps to run and login heroku in your terminal -heroku autocomplete --refresh-cachethen -heroku autocomplete -
Deploying to heroku steps: After installing heroku cli tool, we can:
- login in terminal by running
heroku loginwhich will redirect us to browser and once you login there, the logging in will be done in your local terminal too - Dealing with database
In the
configfolder there isdatabase.ymlfile (yml: Yet another Markup Language) which is whitespace sensitive like python so anything indented below something, it belongs to it like a JSON object but, it does not use curly braces or quotations/config/database.ymland from this link (https://devcenter.heroku.com/articles/getting-started-with-rails6) go down to finddatabase.ymlconfiguration for production modeNote: if you are using
sqlitegem instead of postgres(pg), you will need to use pg for production so, move thesqlitegem into development gems and addpgto production group gems then dobundle installifbundle installfails and asks for installing postgres header files which islibpg-devthen run the following commands:cd ~sudo apt-get updatesudo apt-get upgradesudo apt-get install zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev libffi-dev libpq-dev-
run
heroku createcommand which creates some random sub-domain at heroku.com but, we can also request a particular name by runningheroku apps:create <a-unique-name>then visit the link that is generated which is where our app is going for deployment. -
Now if you run
git remote -v, you have a remote now called heroku as well so:- to push to github run:
git push origin master - to push to heroku run:
git push heroku master
so go ahead and push it to heroku. So that, take all my code and push it to heroku. and then heroku has got some git hooks in place where it is detecting that it is a ruby app specifically rails and start installing my gems, so, it is going into my GemFile and install gems. It will then detect my package.json file and will do
yarn installand install any javascript dependencies that are required - to push to github run:
-
With heroku command we can run all rails commands like
heroku run rails db:prepare'prepare' is a new rails command which if the database does not exist, it gonna create it and appropriate tables not by stepping through our migrations but, by looking at our database schema file and make them all at onceheroku run rails db:seed
- login in terminal by running