GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS

Written by thoughtbot

An Explained psqlrc

Let’s walk through my short psqlrc(5) to see what I’ve set, and to inspire you to find your own configuration that fits into your workflow. Here is my complete psqlrc:

\set ON_ERROR_ROLLBACK interactive
\set COMP_KEYWORD_CASE upper
\set HISTFILE ...

Preload Resource Data into AngularJS

Preloading, or bootstrapping, data resources from the server via HTML is a common technique used in JavaScript web development. This technique allows the application to avoid making an extra HTTP request to get that initial data for rendering on the...

Foolproof I18n Setup in Rails

Let’s make I18n on Rails better, quickly and easily. These tips have helped us here at thoughtbot and caught some easy-to-fix but hard-to-track-down mistakes.

Raise an exception on missing translations

When a translation is missing, Rails will fall...

How Rails' Type Casting Works

Have you ever noticed that when you assign a property to an Active Record model and read it back, the value isn’t always the same? Here’s an example:

class StoreListing < ActiveRecord::Base
  connection.create_table :store_listings, force: true do...

Swift Sequences

We’re incredibly excited about the new Swift programming language announced by Apple at this year’s WWDC. As a way of experimenting, we’ve begun looking into what it would be like if we rewrote Liftoff, our command line Xcode project generation/configuration...

How to Share a Session Between Sinatra and Rails

As Rails developers, we run into Sinatra apps all the time: gems such as Resque which expose a dashboard via Sinatra, legacy Sinatra apps that run alongside a main Rails app, and Sinatra APIs embedded within a Rails app, to name a few examples. Here...

iOS Text Kit Basics

Apple's Text Kit framework, added to iOS 7, lets you customize layout of rich text in your apps in a variety of ways. This will show you how to get started by implementing a multi-column view using Text Kit.

Back to Basics: Regular Expressions

Regular expressions have been around since the early days of computer science. They gained widespread adoption with the introduction of Unix. A regular expression is a notation for describing sets of character strings. They are used to identify patterns...

Thinking in Types

A colleague of mine was stuck attempting to do something in Haskell that seemed conceptually simple but resulted in a type error. While a particular form of polymorphism, common in object-oriented languages, translated very well to Haskell, a related...

Back to Basics: Writing SQL Queries

Almost all applications store data in one format or another somewhere. Us developers spend a lot of time thinking about our data. In a most cases we end up storing that data in a relational database. The advent of the ORM has made writing raw SQL...

Extract Mostly-Constant Data from the Database

Using database-backed mostly-static models in our applications can cause coupling and performance problems. Extracting that data to Ruby constants helps to resolve those problems.

Example

Consider the following database tables and their data:

  • subscription_plans

Introducing Hound

We’re pleased to announce Hound, a hosted service that comments on Ruby style guide violations in your GitHub pull requests.

Hound is currently free and available for public and private GitHub projects. We intend to charge in the near future to ensure...

Back to Basics: Writing Unit Tests First

The value of unit tests and TDD are well documented. Unfortunately, it’s still daunting to start practicing it. Here’s a primer.

Our desired code

We need to write a method that:

  • takes a string as an argument
  • reverses the string
  • saves the string...

What's new in edge Rails: Active Record enums

In an Active Record model, usually you will have a column that can only have a set of pre-defined values (such as a status column). Normally, you would define a constant for those values as well as several helper methods like the following example...

Welcome Aboard: You're Riding iOS on Rails!

When I sat down to write my first API with Rails, I was overwhelmed with the abundance of options available to me. From ActiveModel::Serializers to JBuilder to Rabl to simply calling .as_json, just choosing which library to use for rendering JSON was...

A Closer Look at Color Lightness

As much as we strive to control every detail of what we build, we are sometimes left with little choice but to leave some design decisions to algorithms. The challenges associated with these decisions become a lot more significant when human perception...

Liftoff 1.0

Way back in January of 2013, we released Liftoff to help developers quickly configure Xcode projects. We used it heavily internally, but felt like it was only solving part of the problem. So we’ve improved it, and are proud to announce Liftoff 1.0...

Printing Ralph

I have a 3D printer. It’s a lot of work, but is also a lot of fun. It’s fun because turning 3D models into actual, tangible objects is just cool. It’s work, because it requires a lot of tinkering to get it right. You need to churn out a lot of small...

EmberJS with a Separate Rails API

We just wrapped up a large client project using EmberJS and we learned a few things that are interesting to share.

Ember made this project easier. There are times that a JavaScript framework is unnecessary and there are times that it makes the code...

Avoid the Three-state Boolean Problem

Quick, what’s wrong with this Rails migration?

add_column :users, :admin, :boolean

Yep - it can be null. Your Boolean column is supposed to be only true or false. But now you’re in the madness of three-state Booleans: it can be true, false, or