zargony.com

#![desc = "Random thoughts of a software engineer"]

Using ruby-gettext with Edge Rails

The more I read about the various new features coming up in Rails 2.0, the more I couldn't resist... and finally, a few days ago, I switched over to Edge Rails with my current project.

Switching to Edge Rails was easily done, however after fireing up /script/server and doing the first request, I was presented with a 500 Internal Server Error.

DISPATCHER FAILSAFE RESPONSE (has cgi) Sun Jul 29 12:43:56 +0200 2007
  Status: 500 Internal Server Error
  You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.\[]
    /usr/lib64/ruby/1.8/cgi.rb:1165:in '\[]'
    /usr/lib64/ruby/gems/1.8/gems/gettext-1.10.0/lib/gettext/locale_cgi.rb:26:in 'system'
    /usr/lib64/ruby/gems/1.8/gems/gettext-1.10.0/lib/gettext/locale.rb:88:in 'system'
    /usr/lib64/ruby/gems/1.8/gems/gettext-1.10.0/lib/gettext/locale.rb:96:in 'default'

After some time of debugging, it turned out to be ruby-gettext, which I use for I18N, that causes a NoMethodError on each request during init-gettext.

Read more...

Paginating special queries

The will_paginate plugin for Rails is one of the best pagination plugins I know of and I like the ease of using it. Instead of using Model.find, simply use Model.paginate(:page => x) and you'll get back a collection that behaves like an array and can be displayed in views like any other collection. Additionally the returned collection has some new methods (like page_count and total_pages), which are useful to display pagination links. Installing the will_paginate plugin adds the pagination class method to all models; it even works with automatic finders: e.g. you can use Model.paginate_by_attr, which will paginate queries for Model.find_by_attr.

However, pagination can become tricky if you want to paginate collections returned by special queries...

Read more...

Welcome

Welcome to my first post in my new Blog.

Finally I managed to get my new Blog online. I'm looking forward to do some posts here from time to time, covering problems or ideas I encounter during my projects (which most probably will be related to Ruby on Rails development or general Linux administration stuff).

Read more...