Since Geoinformatics department have requested a Map Archive application, I’ve decided to implement it based on Ruby on Rails. Due to the nature of server problems occurred over the past months, a reliable platform was needed to demo our progress. Heroku seems to be the right choice. However, with lack of information and experience on how to work with Heroku, I’ve decided to write a short how-to on Rails and Heroku.
Let’s start from here:Heroku Devcenter
Step #1 Gemfile:
rails new AppName
We don’t need the usual Unit:Test stuffs on production environment, although, you heavily rely on them during development.
By default Rails project skeleton provides Sqlite database connection in database. However, Heroku supports Postgresql for you as add-ons. Visit Heroku Postgresql Add-on you could create your own database.
Note: For development, it’s rather more convenient to use Sqlite, thus we must change our Gemfile to
1 2 3 4 5 6 | group :development, :test do gem 'sqlite3' end group :production do gem 'pg' end |
group :development, :test do gem 'sqlite3' end group :production do gem 'pg' end
As for Webserver, for development and production thin is recommended.
gem ‘thin’
Step #2 Heroku init:
Presumably you’ve already got a heroku account.
Let’s Login:
heroku login
Create an application
heroku create
Check your application on Heroku Application store
Step #3 Git:
Initialize Git repo
git init
You could work with both Heroku and Github repositories at the same time.
Add Github and Heroku repositories:
git remote add github https://yourgithub.repository
git remote add heroku git@heroku.com:your_application_repository
Note: Your application repository can be found in heroku application settings panel.
After making codes changes, you could try out your code in production environment by pushing the changes on heroku.
git status
…
git push heroku master
Step #4 Twitter-Bootstrap:
By using Twitter Bootstrap Gem, just follow the instructions on Github page.
Note that, precompile assets could cause many problems during deployment or running errors. In order to avoid these errors, the following modifications must be made in application.rb and production.rb files:
1 2 3 4 5 6 | # config/application.rb # Heroku requires this to be false config.assets.initialize_on_precompile=false # config/environment/production.rb config.assets.compile = true |
# config/application.rb # Heroku requires this to be false config.assets.initialize_on_precompile=false # config/environment/production.rb config.assets.compile = true
Notes:
- Before doing anything with heroku, Do Log in
- Don’t forget to run
bunlde install
before commit. - Check errors by:
heroku logs
. - Do keep your source code in sync with github and heroku repositories.
4 Responses to “Let’s Rails on Heroku”
Great post Binh! Thanks!
Thanks mate! BTW a new post is coming on “full text search” technology
Thank you very much for the information https://dw.kz/forum/?PAGE_NAME=read&FID=13&TID=5249&TITLE_SEO=5249-gde-nayti-kazino&u=1343
Thank you for the material, I have already read it several times. https://issuu.com/mostbetazsite