zargony.com

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

Migrating from Apache to Lighttpd with name-based virtual hosts and SSL

This weekend, I switched our webserver from Apache 2.2 using name-based virtual hosts to Lighttpd 1.4.18. This was something I wanted to do for month now, since Lighttpd seems to be much easier to configure and maintain when it comes to name-based virtual hosts, FastCGI applications (like Ruby on Rails) and SSL. Since Lighttpd gains more and more popularity, there were almost no problems migrating from Apache to Lighttpd. Especially name-based virtual hosts are easier to configure in Lighttpd.

Read more...

Links in gettext translated strings

If you use gettext in your web application, you'll sooner or later have to face the problem of handling links that should be embedded into a translated text. What can easily be done in a normal, non-localized template with ERb, can become a nightmare if used extensively in localized templates. However you can prevent yourself (and your translators) a lot of nightmares by using a small helper method.

Read more...

TMail create_forward fixed

A minor bug in TMail (which is used in Rails' ActionMailer) got fixed finally.

About 2 years ago, I reported bug #6015 to the Ruby on Rails bug tracker. TMail's createforward method always returned the first body part of a newly created forwarded mail instead of the forwarded mail itself. Therefore the createforward method was practically useless. At that time, the ActionMailer and/or TMail developers didn't seem to be very active. Well... nobody cared about this for about two years.

After I heard that TMail got a new maintainer, I gave it another try and submitted bug #15445 to the newly created TMail bug tracker. Mikel (who is the new TMail maintainer) applied and tested a fix, so the upcoming TMail version will come without this bug. Thanks a lot, Mikel.

Let's hope this fix will make it into Rails 2.0 so that I can dump one more workaround in my application soon.

Read more...

Paginating special queries with HasFinder and will_paginate

Trying to paginate special queries gave me a headache for quite some time. As summarized in one of my previous blog posts "Paginating special queries", custom finder methods do not work without problems if you use the will_paginate plugin.

There are several plugins that make life easier when you need custom finder methods to do special queries in your models. Widely known are scope_out and scoped_proxy. Both of them are great plugins with different features, but unfortunately neither of them work out of the box with pagination.

Read more...

Flash not accessible in tests (TypeError: can't convert String into Integer)

This morning I faced a strange problem when trying to write RSpec tests for a user login action. Trying to setting the flash before doing a request, resulted in an unexpected Exception:

TypeError in 'SessionController logging in with correct credentials should redirect to the url_after_login url if given'
can't convert String into Integer
.../vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/functional.rb:80:in 'flash'
./spec/controllers/session_controller_spec.rb:52:
./script/spec:4:

Read more...

Symbolize attribute values in ActiveRecord

Update: I put together the code below and created a rails plugin from it. It's called activerecord_symbolize on Github.

ActiveRecord does not natively suppport column types of ENUM or SET. If you want an attribute to act like an ENUM, you'll most probably use a string and restrict it to certain values using validates_inclusion_of. However, once you've got used to Ruby, you'd probably prefer to have symbols as values for these attributes. Here's a small and easy-to-use snippet that can be used to symbolize values of any ActiveRecord attribute.

Read more...

Re-syncing a Cherry eVolution Marlin wireless desktop

A few weeks ago, I bought a Cherry eVolution Marlin wireless desktop (it's a wireless, notebook-like keyboard and a laser-mouse, which are both connected to the PC using one little USB-receiver). Last weekend, when I turned on the PC, I realized that keyboard and mouse didn't work anymore. Neither keypresses nor mouse movements got to the PC anymore. Looking at the USB-receiver, I saw the red LED flashing rapidly.

It just looks like keyboard and receiver got out of sync and have to be re-connected or re-synced, e.g. like pressing connect buttons. However, neither the receiver nor mouse or keyboard have any hidden buttons or switches to initiate a re-connect and synchronize them.

I couldn't find any information on the net relating this issue, so I called the support hotline and found out that a rapidly flashing red LED at the receiver does indeed indicate that devices are out-of-sync. A friendly support assistant told me a way how the devices can be connected again.

Read more...

Scope_out feature: default_scope

I suppose, you know the great scope_out plugin for rails. If not, go check it out, since it's really great to define DRY scoped associations. Basically, you can use scope_out to define the scoped associations within the model the scope is applied to. However, what I'm missing is a feature like a default scope that can be applied to the model and scopes the default finder.

Read more...