Howto share Spree authentication/authorization engine

In a project I’m working on I’m using spree as a mountable engine. The host application has its own administration area, and I wanted to share the spree authentication with my app.

Read more...

The right colors for your VIM

I have a lot of Vim colorschemes, and I like to change them very often, reflecting my mood. I needed a way to showcase them all and quickly pick one.

Read more...

Using virtual attributes for multi parameter form helpers in Rails

In a Rails application I am working on, I needed to setup a form with a field with a non-standard behaviour. The field represents a Date object, so the date_select FormHelper looked great; however, the date to display was not the actual date to be set on the database, but the day before. Changing all the data on the DB was a bit risky, so I had to stick with this requirement. I decided to use a virtual attribute to do this, as it seemed the most elegant solution, so I wrote this in my model:

Read more...

Machinist vs Factory Girl: Machinist win!

Today I decided to verify if Machinist could be a good replacement for Factory Girl. In our project, we have a big problem with Factory Girl: even if you tell her not to hit the database, using the Factory.build method, if an object has associations, these are saved on the DB. And this causes a huge slowdown in specs using factories. We’ve been using Factory Girl for nearly two years, and if we could find a way to stop him hitting the DB, we could really have a huge improvent in our test suite running time.

Read more...

Howto run a rake task in sandbox mode

If you have a Rails rake task that somehow changes your DB data, but you want to be sure that the DB will be rolled back to its previous state after the rake task has completed, you can simply include this snippet right after your task definition:

Read more...

Rails 3 scopes with HABTM (has and belongs to many) relations

There are already many posts about this, but maybe this simple example will help you understand this subject even better.

Read more...

invalid option: with pg dir=/opt/PostgreSQL/9.0

I’d bet a lot of ruby devs actually found themselves stuck in this problem. You checkout a github repo, you run a bundle install and = duh = a gem cannot install because of a missing library. You’re sure you’ve already installed the library or dependency or whatever, but in a different path from the standard one (in this example I’m talking about PostgreSQL installed via the graphical installer instead of the ubuntu apt repo); so you issue the command

Read more...

Format the results of a MySQL query like MySQL! In Rails!

It may happen that you need to display the results of a MySQL query on a page. E.g., your customer asks you to add a report on a page, and you don’t want to build a custom template, but just write the query and see the results.

Read more...

Vim for Rails Developers, by Ben Orenstein

Codeulate Screencasts

Read more...

TextMate Syntax Highlighting Howto: A simple todo list

Today I wanted to add a syntax highlight for my todo list favourite format to TextMate.

Read more...