Get your Ruby-Sinatra App on Heroku

Get your Ruby-Sinatra App on HerokuKenneth StewartBlockedUnblockFollowFollowingJun 11I couldn’t find any clear guides to launching Ruby-Sinatra apps on Heroku so I decided to write one.

The first step you’ll need to take is create a Heroku account.

That’s fairly straight-forward so I wont get into it.

Once you’ve done that you will want to go into command line and install a bundler and heroku.

First the bundler:gem install bundler.

Then install heroku:brew install heroku/brew/herokuYou will then be prompted to log into Heroku by the command-line.

Once you’ve done that you should create a new Heroku repository.

heroku createYour Heroku Project will the be given a random name — Adj + Geographical-Feature.

You should also be able to see it if you go to >> https://dashboard.

heroku.

com/apps.

Now that you have that set-up you will need to add a couple files to your project to tell Heroku how to run it.

You will need to touch 3 new files in the command line: config.

ru | Procfile | GemfileThe only gems I am using in my Gemfile are ‘pg’ and ‘sinatra’, so my gemfile looks like this.

source ‘https://rubygems.

org'gem ‘sinatra’gem ‘pg’, ‘~> 0.

18’The congfig.

ru file is also very simple.

It looks like this:run Sinatra::ApplicationNext is Procfile.

This gives Heroku the commands it will need to run your app.

This should include the command you type into your command line to run your app locally.

web: bundle exec ruby app.

rb -p $PORT‘app.

rb’ is my main controller file, if yours isn’t named ‘app.

rb’ you will need to change it.

Only a few more steps to go.

Back in command line you will need to do a bundle install to setup a Gemfile.

lock.

bundle installYou should now have a Gemfile.

lock in your folder.

It should look like this:You can now launch to Heroku!.First add, commit and push all your files to github and then push to Heroku with the following command:git push heroku masterNow, your app probably won’t be working at this point.

You still need to set up your database.

Go to your Heroku Dashboard ::> click on Resources ::> click on Heroku Postgres.

Once you are in the postgres database dashboard go to setting and then click on ‘View Credentials…’.

Here you will get all the data you need to access your database.

Copy and paste them into your sql runner, it should look something like this.

Once you have done that you will need to create some tables before you seed your database.

You can do this by running your .

sql folder in on Heroku’s database.

To do this you can go back to credentials and copy the Heroku CLI.

Run your sql file like this.

<Your Heroku CLI> < db/<your_sql>.

sqlYou can then seed your database:Ruby db/seeds.

rbAnd that’s you done! … Hopefully.

.

. More details

Leave a Reply