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...
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...
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...
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...
Did you ever want to create multiple models in one action? E.g. if your user model has many email addresses, create a user record and his first email address when he signs up... Nick of Pivotal Blabs wrote a nice article about it -- but it almost drove me to despair this morning when I was trying to break it down to my user and email addresses model.
Read more...
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...
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...
Capistrano 2.0 does not write a revisions.log anymore when deploying your application. However, I liked the revisions.log, because it gives you a clear history of which revision you deployed to your servers at which time. Therefore I wrote a little Capistrano recipe which updates an old-style revisions.log whenever you deploy or rollback your appliaction.
Read more...
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...