6 Jun 2008, 2:04pm

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!!!

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.

9 Apr 2008, 1:27am

by Ariejan de Vroom
leave a comment

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
17 Dec 2007, 9:00am

by Link Pilot
leave a comment

RSpec 1.1 Released: Now Supports Rails 2.0

The team behind RSpec, a Behavior-Driven Development based “testing” library, have announced the release of RSpec 1.1.0. This will be of particular interest to Rails 2.0 developers as support has now been added, along with interoperability with Test::Unit. RSpec 1.1 also includes a Rails tool called “RailsStory” that allows you write “user stories” that can be tested out on the fly.

26 Sep 2007, 10:24am

by Ariejan de Vroom
leave a comment

Flash not clearing after a request?

We all know “The Flash” to be a very useful tool in almost every application we write. What does “The Flash” actually do?

The flash provides a way to pass temporary objects between actions. Anything you place in the flash will be exposed to the very next action and then cleared out.

Well, that’s all nice, but what if you notice that your flash is not cleared, and is shown in one or more subsequent requests as well? more »

17 Sep 2007, 9:56am

by Ariejan de Vroom
leave a comment

RailsConf Europe 2007!

Well, after a long trip, I arrived at my hotel yesterday in Berlin. Today I, and my mates from Kabisa, have joined RailsConf Europe 2007. I don’t think I’ll be giving a full, in-detail report of everything that happens, but I will let you know anything worth your (and my) time.

If you happen to be in Berlin these days, feel free to drop me an e-mail at ariejan at ariejan.net and maybe we can have chat or something. I hope to hear from you!

1 Sep 2007, 6:38pm

by Ariejan de Vroom
5 comments

Content_for, yield and making sure something gets displayed

You may have heard of a very nice Rails technique that used content_for and yield to stuff custom blocks of content into a layout. For example, in a view you could add a block like this:

<% content_for :sidebar do %>
  This goes into the sidebar when viewing this action!
<% end %>

more »

31 Aug 2007, 8:39am

by Ariejan de Vroom
leave a comment

Blueprint 0.5 Rails Plugin released

A few days ago BlueprintCSS 0.5 was released (read the Olav’s posts here). I’ve updated the plugin accordingly. The most important change is the use of 24 (!) instead of 14 columns.

Installation and usage of the plugin have not changed. See my original announcement for more information.

27 Aug 2007, 7:32am

by Ariejan de Vroom
7 comments

BlueprintCSS Rails Generator

This plugin is no longer available. Blueprint nowadays ships with a very good ‘compress’ script that allows you to generate all kinds of nice BluePrint layouts. Having a plugin to just copy some files seems a bit excessive.

I think that, if you’re a web developer, you’ve seen the BlueprintCSS framework. BlueprintCSS offers quite a bit of CSS code that allows you to quickly and easily build a grid-based layout, using pure CSS.

That’s, of course, all very nice, but you should be able to plug it in into your Rails app. And now you can!

Install my plugin:

./script/plugin install http://svn.ariejan.net/plugins/blueprint

And then generate as many BlueprintCSS layouts as you’d like. To create a layout for your posts controller, simply run the following command:

./script/generate blueprint posts

This will create a posts.rhtml template in app/views/layouts, and add the proper CSS and images to your application. That’s all!

Note 1: You may remove a few lines of inline CSS from your layout to remove the supporting background images.

Note 2: Bugs and feature requests go into Trac.

24 Aug 2007, 1:37am

by Ariejan de Vroom
10 comments

Super Simple Authentication Plugin and Generator

I hereby proudly announce my Super Simple Authentication plugin and generator.

All right, what does it do? Sometimes you need to protect your actions and controllers, but you don’t want to go about installing restful_authentication or anything like that. Adding a simple password for certain actions would suffice. So, I wrote a little plugin that can generate some code for you that allows you to easily protect your app with a simple password.

To get started, you must first install the plugin in your rails application:

script/plugin install http://svn.ariejan.net/plugins/super_simple_authentication

When the plugin is installed, you may generate your SSA controller. This controller verifies your password and makes sure you stay authenticated for the duration of your visit.

script/generate super_simple_authentication sessions

Your password is located in config/super_simple_authentication.yml. Change it.

In the SessionsController, you’ll find an include statement. Move this include to your application controller:

include SuperSimpleAuthenticationSystem

The generator automatically added routes to your config/routes.rb file. If you want easy access to login and logout functionality, add these two lines to your config/routes.rb file as well:

map.login  '/login',  :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy', :method => :delete

You can now protect you actions and controllers with a before_filter:

# Protect all actions in the controller
before_filter :authorization_required
 
# Protect all actions, except :index and :recent
before_filter :authorization_required, :except => [:index, :recent]
 
# Protect only :destroy
before_filter :authorization_required, :only => :destroy

In your views, you can check if you are authorized or not with authorized? E.g.

<% if authorized? %>
    # ... do secret admin stuff
<% end %>

Please visit http://trac.ariejan.net to report bugs. Ariejan.net will keep you updated on new major version. Please subscribe to the RSS Feed.

I hope you enjoy this plugin. Please post a comment if you use it in your project, or if you just like it. Bugs, feature requests and support requests should go into Trac