A Speedier Rails App using Rails 3.1 + Arel 2.0

Before (Rails 3.0.1pre stable branch + Arel 1.0.1):

After (Rails 3.1.0 master branch + Arel 2.0.0dev master branch:

Thanks to the awesome work done by Aaron Patterson (@tenderlove) and others. :-)

UPDATE:

After Aaron Patteron’s tweet, I ran the tests again on Rails 3.0.1pre stable branch + Arel 2.0.0dev master branch, and the result blew my mind:

`bundle: command not found` or `Could not find RubyGem bundler (>= 0)` During Capistrano Deployment? No Problems!

Don’t you just hate it when you get the following errors during a Capistrano deployment?

bundle: command not found
Could not find RubyGem bundler (>= 0) (Gem::LoadError)

In fact, even if you don’t use bundler, you might still get errors like this:

rake: command not found
Could not find RubyGem rake (>= 0) (Gem::LoadError)

It turns out this has something to do with the $PATH and $GEM_HOME variables.

So here’s the quick fix.

Log in to your deployment server, as a root user, add the following line to /etc/ssh/sshd_config:

PermitUserEnvironment yes

Don’t forget to restart ssh:

/etc/init.d/ssh restart

Now, log in as the deployment user, and create ‘~/.ssh/environment’ with the following content:

PATH=/usr/local/rvm/gems/ruby-1.9.2-p0/bin:/bin:/usr/local/rvm/rubies/ruby-1.9.2-p0/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GEM_HOME=/usr/local/rvm/gems/ruby-1.9.2-p0

* The above paths are for your reference only, obviously you need to work them out for your server environment. The only thing you need to make sure is that the GEM_HOME’s path matches one from the PATH.

Now, to verify this all work, you may use cap shell to start a new shell session and try out your commands.

[Rails] Introducing Datamappify - ActiveRecord Without DB Migrations

Introduction

ActiveRecord is without doubt the de facto ORM library for Rails and many Ruby web frameworks. Many developers however, do not like database migrations and prefer to use DSL for data mapping. Datamappify is created with the sole purpose of getting rid of the DB migration headaches.

Why Not DB Migrations?

Well, depending on your specific project, DB migrations might create more trouble than it’s worth. Besides, your code is already version controlled, so why create a separate version control for your DB schema?

Why Not Use DataMapper, Sequel, etc?

As stated in the introduction, ActiveRecord is the most popular ORM in the rails community, it is actively developed and battle-tested. If your only grief with ActiveRecord is the DB migrations, why not just eliminate it be happy? ;)

Go check out the code!

[Rails] Releasing Action Throttler, A Rails Plugin for Throttling Actions

Sometimes we would want to throttle certain application actions. For instance, a user should only be allowed to send x amount of emails to other members of the site in order to reduce the spam risk.

Since this is a quite common task, I thought I might as well make it as a Rails plugin for better code reusability.

I am now releasing Action Throttler, an easy to use Rails plugin to quickly throttle application actions based on configurable duration and limit. Go check out the code now! :)

There is currently no tests for the plugin but I will be adding rspec specs to it soon.