Filipe Costa

Read this first

`pointer-events: none;`

I was doing some front end work these days and I had to “disable” a link with some JS code. I had a class to style the link, but it was still clickable.
I googled for disabling a link and found this css trick. I didn’t know it until then.

.disabled {
  pointer-events: none;
}

That solved my problem, simple as that.

View →


3-state Boolean field

I’ve been through a piece of code today that reminded me this specific case on Rails Migrations:

add_column :table_name, :column_name, :boolean

How does that look to you? Ok? Well, it seems ok, right? If that wasn’t a boolean field, it would be just fine, although for boolean fields, that’s not correct. This way we have 3 possible values for that field, true, false and nil.

Avoiding the problem

To avoid this, we must add the option null: false, which will leave you with only the two possible values for booleans, true and false. Great, we have that fixed.

Wait, what?

In case you have previous data on this table, your migration might not be able to successfully execute. The reason is that your database does not know what to put on that newly added column, for those previously entered rows. The default behaviour is to just add NULL, although we just added a constraint nil: false...

Continue reading →