Complex query filters with ActiveAdmin

I had expected this topic to be long, complicated and extremely difficult, but I was pleasantly surprised to learn how dead simple it was to accomplish using tools already built into ActiveAdmin, and more specifically, MetaSearch.

Here’s the scenario: My application contains a model which has attributes for both the start and end of a range. Specifically, a Production has both start_date and end_date columns which together define the span of time over which that production occurs. I wanted a way to search for productions in a time period, but I wanted to see any productions where the range of dates for the production fell within the query window I specified.

Let me give a better example. I have a production that begins on Dec. 1st and runs through Dec. 5th. That range, 12/1 – 12/5 is the production window. I want to query for any productions occurring between Dec. 2nd and Dec. 4th. So the query window is 12/2 – 12/4. The query window is more narrow than the production window, and so simple filtering on start_date or end_date won’t work.

Continue reading

New look for Rails version

Status

Starting today, the forthcoming Rails version of this site has a new look. Like any good UI, it’s a constant work-in-progress, but I think the changes applied here look good enough to run with for now.

I haven’t bothered to verify that the new look works across all browsers, but I’m not doing anything terribly fancy, so it should just work. Anyway, check it out: http://rails.living5to9.com

Slug::Engine

While developing my blog in Rails, I resolved to include a mechanism for assigning arbitrary, SEO-friendly URLs to my content, similar to what the Path module in Drupal does. Such a feature is common in popular blogging engines like WordPress and Blogger, so it didn’t seem such a far-fetched feature.

Implementing the functionality turned out to be much more difficult that I had first imagined. The problems I encountered, which led me deep into the bowels of Rails to understand and resolve, have left me with a vastly improved understanding of how a Rails application works. Below, I detail some of those problems and how I overcame them. Continue reading

Rails Routes: match and mount

While working on the SlugEngine built into this blog site, I came across a note-worthy errata in the book Rails 3 in Action.

Section 18.3.1 states that the following two lines in config/routes.rb are functionally equivalent:

# method one
mount Foo::Bar, :at => 'foo/bar'

# method two
match 'foo/bar', :to => Foo::Bar

These two routes are similar. In fact, mount in turn calls match to complete the route setup. However, the difference (as of Rails 3.1.1) lies in the options that mount passes along to match. Continue reading

Upgrading to Rails 3.1 on Heroku — Part III: Rails

Upgrading to Rails 3.1 on Heroku — Part III: Rails

Up to this point in this series I have been focused on some of the prerequisites to upgrading Rails to 3.1. In this post, all of those requirements have been satisfied, and I can finally get to the meat of the task: upgrading the Rails gem! Continue reading

Building a Blog

A few months ago, after purchasing a Nikon D7000 DSLR camera, I decided I should really get serious about maintaining a blog on which to not only showcase my photography, but also to showcase myself, as a photographer, a developer and as a person. I want a “portfolio of me”; something a potential client or employer could look at that would represent who I am and what I can do.

I have started and abandoned blogs in the past, and have generally lost interest shortly after getting the blog up and running, making it look and feel like something I like, and making a few posts. But this time had to be different. Continue reading