Ruby breakfast

Technical tricks from a freelance Ruby & Rails developper living in Nantes, France.

How to disable apache2 from running on startup

I was trying to remove the following warning from passenger-memory-stats, I had to install apache2 but without running it :

*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename,
or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.

Solution (found here) :

Tiny trick : lazy i18n-aware title helper

You’re probably already using a title helper, storing your page title into an instance variable in order to output it in the layout.

I’m using the following trick to use by default the “.title” i18n key of the current page, that’s useful only for static-title pages.

No more <% title(“.title”) %>, let’s simply <% title %> it !

Dealing with permalinks in Rails

When you want to improve your SEO karma, you have to play with your urls. You can use norman/friendly_id, but you can also do it yourself, it’s quite simple: just rewrite to_param method.

We can go further by creating a column for the permalink and using a hook to fill it:

On the controller side, it remains the same thanks to this Ruby behaviour:

More interesting, we can avoid duplicate content by redirecting urls with a bad permalink:

Update

Thanks to Henryk Nye, I’ve improved my :redirect_if_moved method (maybe should I rename it :redirect_if_better).

Direct quote:

Using :overwrite_params will ensure any additional parameters are unchanged.

Have SEO fun!

Moroccan flavour

An illustrated extraction of my holidays in Morocco. See all pictures on my Flickr gallery.

Ruby app servers : what’s hot ?

So you’ve got a fresh new Rails app to deploy and you’re wondering which Ruby app server to use.

The old school way : a bunch of single process workers monitored (by Monit or God) and reverse proxied by (usually) Nginx. A little old-fashioned because it needs a serious monitoring configuration in order to deal with memory bloats, long actions, deployments, load balancing…

The simple way : Phusion Passenger (aka mod_rails). If you’re sticked with PHP apps on your server, or basically if you prefer Apache, this is the best solution : like adding “PassengerEnabled On” into your virtual host declaration. It works out of the box without having to deal with worker pools.

My personal preference goes to the Nginx version of Passenger. Nginx is a memory-saving, stable and fast web server. The install is dead simple if you let Passenger compile itself a fresh new Nginx instance. You got the best of both worlds : performance (Nginx) and simplicity (Passenger).

I’m looking forward to Passenger 3, teased by some of Ninh Bui’s tweets : awesomeness and performances… Can’t wait!

An alternative, fresh but unproven server : WebROaR is an all-in-one web+app server introduced as the most performant solution by the authors (“5 to 55% faster than other deployment stacks“). I feel a mistrust from the Rails community, maybe because it was released in the middle nowhere, but you should have a look at it.

Unicorn is a fast server for Rack-based applications, based on Mongrel and strongly inspired by the Unix philosophy : do one thing but do it well. It needs to rely on a buffered reverse proxy (Nginx) to deal with slow requests. Used by the Github folks as described here.

JRuby highlights enterprise perspectives : you can now deploy your Rails app on JEE app servers such as Glassfish.

In short, for general purposes my preference goes to Passenger for Nginx. Easy install, small footprint, fair performance : don’t need more. I would consider using Unicorn for high performance context.

404 to the rescue

There are the “not found” related exceptions rescued by 404 in my rails apps:

(The Peugeot 404 by Pleuntje)

Hello world, this is a ruby devlog birth!

Hello, Ruby developpers and curious people! I’m a former Java and PHP developper, now happy to work with Ruby and agile methods.

This place will host some of my Ruby & Rails related tricks and thoughts. Welcome onboard.

I’m french but I’ll write in english in order to improve my technical writing skills. The following picture was shot from my flat in Rezé, south of Nantes, west of France.