onrails.org home

Moving onrails.org to Typo 5.4.x, Rails 2.3.8 on Heroku

So why Heroku and why not leave my server on slicehost? I don't have any issue with the slice but I want to upgrade the version of Typo just to stay uptodate and while at it wanted to explore a little. So of course I found an article on Getting Typo 5.4 running on Heroku So I gave it a try. The interesting part is that onrails.org has been around since forever and I also had tomigrate the database. Onrails.org was running on a version of Typo 4. h2. setting the blog up locally First I've downloaded my older typo MySQL database and restored it locally. I've copied Typo from here or you can clone the Typo git repository.

$ git clone http://github.com/fdv/typo.git 

I changed the database.yml to point to my database. Did a rake gems:install, followed by a rake d:migrate and had now a local install of my blog. h2. creating a heroku app The goal was to try to deploy the blog to heroku. So here you can create an empty

$ heroku create onrails
$ git init
$ git add .
$ git commit -m "Adding onrails.org using typo 5.4.4"

I then followed joels' article to "heroku"fy Typo. So I basically created afew empty folders and replaced FileUtils by FileUtils::NoWrite. Note sure if that last change would cripple Typo but things seems to work fine. Then I created a .gems files that is used by heroku instead of Bundler.

rails = 2.3.8
bluecloth ~> 2.0.5
coderay ~> 0.8
mislav-will_paginate ~> 2.3.11 —source gems.github.com
RedCloth ~> 4.2.2
panztel-actionwebservice = 2.3.5
addressable ~> 2.1.0
mini_magick ~> 1.2.5

Finally I deployed the app with an empty database:

$ git remote add heroku git@heroku.com:onrails.git
$ git push heroku master
$ heroku rake db:migrate # with empty db

That's it that gets you an install of Typo on Heroku. Note, keep reading for a few gotcha's I found in regards to Rails 2.3.8. h2. Rails 2.3.8 on heroku At the time of this writing Rails 2.3.8 wasn't the default on Heroku, but fortunaely they support a different stack with Rails 2.3.8. To switch I just had to do the following:

$ heroku stack:migrate bamboo-ree-1.8.7

h2. Migrating the local MySQL database to Heroku's Postgres database. It's a rather straight forward process…just do

$ heroku db:push

This converted the database and replaced the remote database with my local data on Heroku. It converts my MySQL database to a Postgress database without having to speify anything…But there was on gotcha. The Sidebar table id column turned out as "text" instead of an "integer". And this caused some of the admin functionality to fail, i.e. reconfiguring the sidebar. The other tables where converted correctly and I saw that the local Sidebar id column was slightly different than the other id columns. For some reasons the sidebar table id column type was a "signed int' and that translated to a text field when doing the db:push. So I just unchecked the signed flag ad the db:push went smoothly. h2. legacy permalinks Somehow the articles and category links are all prefixed with "/articles" on onrails.org. I don't know if that was due to some default setting in Typo 4 or due to the fact that I started with a way earlier version of Typo. In any case I preferred to use the new links formats that just drops the "/articles", but that would also mean breaking a lot of incoming links. So I just configured Typo to support the legacy permalinks via these addd routes # Legacy permalink format support map.connect '/articles/:year/:month', :controller => 'articles', :action => 'index', :year => /\d{4}/, :month => /\d{1,2}/ map.connect '/articles/:year/:month/page/:page', :controller => 'articles', :action => 'index', :year => /\d{4}/, :month => /\d{1,2}/ map.connect '/articles/:year', :controller => 'articles', :action => 'index', :year => /\d{4}/ map.connect '/articles/:year/page/:page', :controller => 'articles, :action => 'index', :year => /\d{4}/ # Legacy permalink format support map.resources :categories, :except => [:show, :update, :destroy, :edit], :path_prefix => '/articles' map.resources :categories, :as => 'category', :only => [:show, :edit, :update, :destroy], :path_prefix => '/articles' map.connect '/articles/category/:id/page/:page', :controller => 'categories', :action => 'show' Now the blog supports both new and old formats. Note that the url fo the articles can be modified in the settings, but I didn't find settings for the category permalinks and supporting both old and new format gives me a smooth transition forward. h2. Rails and Issue with Typo workaround? I was getting the following error when doing certain actions on the blog: ActionView::TemplateError (undefined method `interpolate_without_deprecated_syntax' for #) on line #5 of themes/scribbish/views/articles/coment.html.erb: So I assumed this was some compatibility between Typo and Rails and Typo had a workaround defined in the environment.rb file file. As I use Rails 2.3.8 I disabled that workaround and everything seems to work again: So I just removed the followed lines from the enviroment.rb file:

class I18n::Backend::Simple
def interpolate(locale, string, values = {})
interpolate_without_deprecated_syntax(locale, string, values)

h2. custom domain I'm sure there are a few more details I missed and hope my readers will point them out, but let's jump and turn the switch on. So you need to switch on custom domains on heroku as follows:

$heroku addons:add customdomains
$ heroku domains:add www.onrails.org
Added www.onrails.orgas a custom domain name to onrails.heroku.com
$ heroku domains:add onrails.org
Added onrails.orgas a custom domain name to onrails.heroku.co

Then I went on to pointed my dns to Heroku. The move is complete but the dns change to point to heroku still may take some time. So if you see the Scribbish theme you are still on the old server and if you see the Elegant Grunge theme you are right here on Heroku. Enjoy, Daniel UPDATE 1: the dns updated www.onrails.org and onrails.org at different time. And all the images of the new sites where using urls of the old site and everything looked pristine. No mre…So a hidden issue is that Typo let's you upload files like images which are stored in the resources table and also copied to to the public/files folder. This is a convenient way to serve files and images for your blog entries. Well, that won't work very well while on heroku especially since we really made the file system read only. I need to read more on how to enable page caching on Heroku and see if it is compatible with Typo. If not… I will need to revert back to my previous host. For now I'll jst add the files via git…and that's not a solution.

Fork me on GitHub