Find the newest file from shell

Get the most recently modified file in a directory for shell script processing using ls -1tr and tail -1.

Force RubyMine to notice file system changes

RubyMine may lag behind file operations done outside the IDE, leaving the project tree and file list stale. sync or File → Synchronize forces an update.

Setting nil values in Machinist blueprints

Blueprint attributes in Machinist can keep inherited values unless nil is wrapped in a block; editor { nil } clears the master value, plain nil does not.

Dealing with ActiveRecord::RecordNotSaved

ActiveRecord::RecordNotSaved often comes from a callback method returning false, especially when the last assignment is boolean. Ending the method with true avoids the save being aborted.

Here’s what we’ve learned about doing UI for mobile web apps with WebKit

Lately, we’ve been exploring ways to offer web apps that perform like native apps on mobile devices. For this short sprint we targeted mobile WebKit browsers—especially the default browsers on iOS and Android—because of their widespread use and excellent support for HTML5 and CSS3. Here are a few things we’ve learned along the way.

Match strings in a given order with Cucumber and Capybara

Verify that page text appears in a specific sequence while ignoring HTML markup, using a Cucumber step for plain-text order checks.

Preload tags with acts-as-taggable-on

When you do tags with acts-as-taggable-on and want to preload associated tags, you can do so with

TaggedModel.scoped(:include => :tag)

Note however that this will only prevent tagged_model.tags from hitting the database. Using tagged_model.tag_list does not use the preloaded association.

Solve ActiveRecord::MissingAttributeError "missing attribute: foo"

ActiveRecord::MissingAttributeError appears when a query omits a column later accessed on the model, often after using select with too few fields.

Using SSL in Rails 3

SSL in Rails 3 is non-obvious.

Machinist: Refer to another named blueprint inside a blueprint

Named Machinist blueprints can reuse another blueprint’s fields, letting variants combine shared defaults without repeating attribute definitions.

Be careful with Array(...)

Array(...) is a convenient coercion in Ruby, but to_a can split strings and trigger unexpected conversions for non-array inputs.

Deliver Paperclip attachments to authorized users only

Private Paperclip downloads need restricted storage or hashed URLs to keep attachments away from public access. A controller-based delivery path or secret-based paths reduce exposure.

Install the Nokogiri gem on Ubuntu servers

You need to install the following packages before you can build the Nokogiri gem:

sudo apt-get install libxml2-dev libxslt1-dev

Resolve Aspell errors with your Rails application

If you get an error message like that you are missing the Aspell files a specific language:

No word lists can be found for the language "de"

Solve it by installing the proper package, e.g. on Ubuntu:

sudo apt-get install aspell-de

Prevent SSH from timing out

SSH sessions can drop when idle or behind network devices. Keepalives such as ServerAliveInterval and ServerAliveCountMax help prevent disconnects.

Using the full power of have_css

Capybara has_css? can assert selector counts and text content, including substring matches; exact text requires finding the element and comparing it directly.

apotonick's hooks at master - GitHub

Hooks lets you define hooks declaratively in your ruby class. You can add callbacks to your hook, which will be run as soon as you run the hook.

Even with bundler your gem order can be significant

Gem loading order in a Gemfile can still matter with Bundler when gems require application classes or each other during load, and Rails may fail to boot.

An obscure kernel feature to get more info about dying processes

This post will describe how I stumbled upon a code path in the Linux kernel which allows external programs to be launched when a core dump is about to happen. I provide a link to a short and ugly Ruby script which captures a faulting process, runs gdb to get a backtrace (and other information), captures the core dump, and then generates a notification email.

Inline if-then-else in MySQL queries

It can be useful to have a Ruby expression like condition ? positive_case : negative_case in MySQL queries:

UPDATE users SET monthly_debit = IF(subscriber, 19, 0)

Precedence of Ruby operators

Ruby operator precedence determines how expressions bind, affecting arithmetic, comparisons, assignments, and logical conditions when parentheses are omitted.

Generate a strong secret from the shell

Strong secrets for sessions and secret_key_base can be generated from the shell with apg or bin/rails secret.

Taking advantage of RSpec's "let" in before blocks

before :each blocks can use let values declared later, enabling per-context setup without predeclaring variables; local variables inside it blocks do not work.

jsmestad's pivotal-tracker at master - GitHub

Ruby gem that provides an AR-style interface for the Pivotal Tracker API.