- Extending rails.vim Navigation Commands with projectionist.vim
One of my favorite Vim plugins is rails.vim by Tim Pope. And the reason it’s one of my favorite Vim plugins is all of the navigation commands that it gives you for working with …
- Using the PTY Class to Test Interactive CLI Apps in Ruby
I recently created a command line Reverse Polish notation calculator as a programming exercise. It’s interactive, so a user runs the executable and then they are presented with a …
- Webcal Links in Rails with the icalendar Gem
The icalendar gem is a useful way to generate iCalendar files for use with various calendar applications. One thing I couldn’t find good documentation on, though, is how to use it …
- Greatest-Per-Group Query in Rails Using a View Backed Model
In Rails, each model is backed by a table in the underlying database. A view backed model is a model that is backed by a database view, instead of by a normal table.
- Greatest-Per-Group Query in Rails Using a Scoped has_one Assocation
We're creating a table that has a single row per author and then joining it to the authors table, which might sound an awful lot like a has_one association.
- Greatest-Per-Group Query in Rails Using Custom Query Methods
Because Rails dynamically creates attributes on our model for any columns returned by the database, all we have to do is get Rails to execute our modified query when loading our collection.
- Greatest-Per-Group Query in PostgreSQL Using DISTINCT ON
In my Rails apps, I often need to get the largest/smallest/newest/oldest/whateverest element in a model's `has_many` association. Here's how I do that.
- How I Record Programming Talks
I usually record the talks at the Portland Ruby Brigade’s monthly meetings. In part this is because it feels like a shame to have the knowledge contained in the talks not be …
- Rails: Static Pages Using the Controller Route Macro
One of my Rails apps recently took responsibility for serving the home page and marketing pages from an installation of Wordpress, mainly to allow for a site-wide nav bar which …
- Rails: Organizing Controllers with Modules
One of my Ruby on Rails apps has lots of models and a few models that each have lots of has_many associations. For instance, the Company model has 27 has_many associations. …
- Rails: Organizing Models by Attribute
One of the Ruby on Rails apps that I work on has a few models that have lots of stuff in them. The Company model in this app is 311 lines long. Now, I know that won’t break any …
- Rails: Testing for Insecure Admin Routes
I have a Ruby on Rails app with an admin section, as is common for a lot of apps. The admin section is namespaced, so all of the controllers are named something like …
- Rails: Testing for Orphaned Routes
Over time, one of my large Ruby on Rails apps has accumulated a lot of cruft in it’s routes file. In addition to the normal entropy that accumulates in any large app, I didn’t …
- Leveling Up Revisited
I previously wrote about leveling up as a programmer. At the time, I had forked a list of programming achievements originally belonging to Jason Rudolph and left his list mostly …
- Leveling Up
I recently read a blog post by Jason Rudolph about leveling up as a software developer. To paraphrase him, the idea is to: Identify the experiences that advance a person as a …
- Rails: Is the Attribute Actually Optional?
Ruby on Rails model attributes are optional by default. That is, unless you specify otherwise, an attribute is not required for a model instance to be valid. I like to test that …
- Rails: Are the Fixtures Valid?
A common pattern in my Ruby on Rails unit tests is to start with a valid instance of a model, make a change to the attribute I’m testing, then assert that the model instance is no …
- Returning to Computation
Way back in the day, when I was in college, I took a class on basic programming with C++. I only did okay in that class, but the concepts really stuck. There was something about …