Rails on Heroku

I pushed bookmarks-rails project to Heroku yesterday. Thanks to tutorial i don’t have too many troblem during upload to Heroku. Some parts of doc are out of dated and here i write down the steps for reference myself in the future.

  1. install heroku toolbelt from heroku
  2. heroku doesn’t support sqllite3, modify sqllite3 to postgres sql
1
gem 'sqllite3'

to

1
2
3
4
5
6
group :development, :test do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end

3.use thin as production webserver

1
2
3
group :production do
  gem 'thin'
end
  1. run bundle install --without production
  2. In Rails 3.x precompile your assets file, you have to add config.assets.initialize_on_precompile=false to your config/application.rb. Rails 4 ignore this.
  3. run rake assets:precompile RAILS_ENV=production
  4. set config.serve_static_assets = true in your production.rb because we use rails to serve static assets
  5. run git commit -am "your commit message" because only commited source code will be pushed to heroku.
  6. run heroku create appname to create your app on heroku. It requires you input your account,password and your ssh public key(id_rsa).
  7. run git push heroku master. You will see your app running on http://appname.herokuapp.com. Heroku will modify your production datbase connection in database.yml when push to heroku. You don’t need to put the production setting your database.yml.
  8. run heroku run rake db:migrate to create db on heroku

trouble shooting

If you use Twitter Bootstrap, you have to comment out favicon related codes in your application.html.erb. Or you will fail to push to heroku.

1
2
3
4
5
<!--
  <%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %>

  <%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
-->

If you modify the app name on Heroku web site, you should remove your remote branch and re-add.

1
2
3
git remote rm oldname

git remote add newname git@herokuapp.com:yourapp.git

Comments