baan banen Rails Ruby rubyenrails RubyOnRails
by Ariejan de Vroom
leave a comment
Zoek jij ‘n uitdagende baan??
First off, sorry to all the English-reading people, but this post is intended for my Dutch audience.
Even wat updates voor mijn Nederlandstalige publiek. Ik heb wat nieuwtjes voor jullie, dus lees snel verder!
Allereerst wil ik even melden dat ik a.s. dinsdag (10 juni) te vinden zal zijn op RubyEnRails 2008. Dus, ben jij er ook, laat ‘t me even weten! Laat even ‘n commentaartje achter, of nog beter: bel/sms me even dinsdag op 06-17103624, dan spreken we elkaar zeker!
Dan nog even een oproep voor alle Nederlandse Ruby, Java en PHP developers. Als jij echt coole webapps kan (of wilt gaan) maken, dan moeten we praten! Kabisa zoekt namelijk op korte termijn Ruby en Java developers. Ik kan er zelf over meepraten: bij Kabisa werken is leuk, afwisselend en het biedt je alles wat je van een goede ICT job mag verwachten.
Spreek me dinsdag even aan (zie m’n nummer hierboven) als je meer wilt weten over werken bij Kabisa! Of maak gewoon voor de lol even ‘n praatje!
Ben jij ‘n Ruby, Java of PHP developer - en ben jij toe aan een leuke ICT baan? Neem dan ‘ns contact met me op, want ik ben op zoek naar collega’s!
Tot dinsdag bij Ruby en Rails 2008!!!
The migration that cannot be undone: Irreversible Migration
Migrations have up and down methods, as we all know. But in some cases, your up method does things you can’t undo in your down method.
For example:
def self.up # Change the zipcode from the current :integer to a :string type. change_column :address, :zipcode, :string end
Now, converting integers to strings will always work. But, you feel it coming, converting a string into an integer will not always be possible. In other words, we can’t reverse this migration.
That’s why we should raise ActiveRecord::IrreversibleMigration in the down method.
def self.down raise ActiveRecord::IrreversibleMigration end
Now, if you run your migration (upwards), you’ll see it being applied like it shoud. However, if you try to go back, you’ll see rake aborting with ActiveRecord::IrreversibleMigration.
$ rake db:migrate VERSION=4 -- Database is migrated $ rake db:migrate VERSION=3 -- Rake aborted! -- ActiveRecord::IrreversibleMigration
So, if you have things you can’t undo, raise ActiveRecord::IrreversibleMigration in your migration’s down method.
apache apache2 mod_rewrite permalinks rewrite Wordpress
by Ariejan de Vroom
leave a comment
Permanently redirect WordPress pages
After my trip to Mephisto some time back, I noticed that some pages were accessible from different URLs. After moving back to WordPress, these permalinks no longer work.
I’m running WordPress with Apache2, so it shouldn’t be too hard redirect those old permalinks to their new locations. (That’s what rewriting is all about anyway).
Here is the default .htaccess file generated by WordPress:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPressAs I said, it’s generated by WordPress. It would be very unwise to edit this, because our changes might get lost in the future.
The solution is simple. Add another block above the generated one that does permanent redirects. In this example I rewrite pages/svnsheet to http://ariejan.net/svncheatsheet.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pages/svnsheet$ http://ariejan.net/svncheatsheet [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPressFYI, the R=301 means the browser (or search bot) receives a “Moved Permanently” message. L means this is the last rewrite rule to read.
Of course, you can go nuts and add all sorts of funky regular expressions to rewrite URLs.
The nice thing is that WordPress will only replaces the block between the BEGIN and END tags, keeping your rewrites in tact.
Note: don’t forget to restart apache if your rewrites don’t seem to work.
imagemagick libMagickWand magick Rails rmagick Ruby Ruby on Rails RubyOnRails
by Ariejan de Vroom
leave a comment
Debian Etch: RMagick LoadError
If you’re on Debian Etch, you may encounter the following error
libMagickWand.so.1: cannot open shared object file: No such file or directory - /usr/lib/ruby/gems/1.8/gems/rmagick-2.3.0/lib/RMagick2.so
This basically means that the libMagickWand.so.1 file cannot be found. However, it is available on your system. All you need to do to fix it, is tell your box to look in the right place for the file.
To fix this issue once and for all, open up /etc/ld.so.conf.d/whatever_file_is_here. The whatever_file_is_here is named after the kernel you have installed.
In this file, add the following line at the bottom
/usr/local/lib
Save the file and next run the ‘ldconfig’ command. This will reread the configuration file you just edited. Now, restart your Rails app and you’ll notice the error is gone and all is good again.
ldconfig
This change will be kept after you reboot, so you won’t encounter this error any time soon again.
Enabling Trac Email notifications
If you’ve ever reported a but to Ruby on Rails, you’ll have noticed that their Trac has nice email notification feature. And I bet you want that in your Trac as well!
Now, email notification are nothing exotic. You don’t need any plugins, just an outgoing SMTP server and access to your trac.ini file.
In your trac directory open up conf/trac.ini and look for the [notification] header. Make sure you have at least the following settings. Of course, make sure you enter valid values for your situation.
always_notify_owner = true always_notify_reporter = true always_notify_updater = true smtp_always_cc = trac-updates@mailinglist # Optional if you want to archive outgoing emails smtp_enabled = true smtp_from = trac@ariejan.net smtp_from_name = Ariejan.net Trac smtp_replyto = noreply@ariejan.net smtp_user = smtp_password = smtp_server = localhost smtp_port = 25
There are a few more options like ‘ignore_domains’ if you don’t want to send emails to certain domains.
Update: good news for you GMail users! There is a ‘use_tls’ attribute. I think that if you set it to true, you can then specify GMail’s SMTP server to send out mails. Of course, a better solution would be to setup Postfix to relay mail to GMail, and just leave Trac to it’s default ‘localhost’ settings.
Rails Snippet: Caching expensive calls
In Rails, from time to time, you may encounter you have a method you call several times, but which returns always the same result. For example, have the following:
class Person < ActiveRecord::Base has_many :articles def get_approved_articles self.articles.find(:all, :conditions => {:approved => true}, :order => 'approved_on DESC') end end
A query is fired every time you call Person#get_approved_articles. To cache the result of the query during this request, just add a bit of magic
class Person < ActiveRecord::Base has_many :articles def get_approved_articles @approved_articles ||= self.articles.find(:all, :conditions => {:approved => true}, :order => 'approved_on DESC') end end
This will return the @approved_articles value if it exists. If it doesn’t, which is the first time you access the method, the query is run and stored in @approved_articles for later use.
Note: I know it’s much easier to define this kind of behaviour, but it’s just an illustration.
class Person < ActiveRecord::Base has_many :articles has_many :approved_articles, :class_name => "Article", :conditions => {:approved => true}, :order => 'approved_on DESC' end
Here we go again: WordPress 2.5
Okay, here we go then. I’ve managed to drop Mephisto after only a few weeks of service.
As a Rails developer, I liked the idea of running my own blog on something Rails. However, Mephisto was a big disappointment. Especially compared to WordPress 2.5. Mephisto has been on life support for quite a while now, and it’s just too complex to be easy to hack. Now, don’t get me wrong. I love hacking Ruby, but not too much on my blog. It “should just work”.
The reason I skipped to Mephisto in the first place was that my Wordpress 2.3 blog was very slow. I managed to track down the problem to the Twitter plugin, which was next to useless anyway.
Now, with all the new funky stuff in 2.5, I switched back. I haven’t managed to write anything substantial in the past weeks anyway, so it wasn’t a problem to loose one post.
There are many reasons for my not posting substantial stuff lately. One of them being my new hobby: photography (link). Check out my Flickr page and let me know what you think of my more recent photos.
So long for now. Expect more from me soon.
Attack of the Killer Bunnies
Well, here they go then! Just swooping in, eating all the green stuff from your garden!! Someone stop them!
This was taken in the back-yard at Laura’s parents house. The neighbours have about a dozen rabbits, but they are allowed to walk around as they wish, occasionally finding their way into other people’s gardens.
Kabisa Blog
Well, we’ve got our blog up and running at Kabisa now! Our entire team will be posting interesting Ruby, Rails, Java and Subversion articles that may be of very good use to you.
Check out the blog now on http://blog.kabisa.nl or grab the RSS Feed to stay up-to-date.
For You: Merry Christmas and a Happy 2008!!!

We (Laura and I) wish you a very merry Christmas and a happy 2008!
I hope to welcome you back on Ariejan.net in 2008. Happy Holidays!

