Ernie Miller

No, I don't work in NYC, DC, or the valley, and I'm cool with that.

RSS Feed

Tag Archives: ruby

The MetaWhere 2.0 Rewrite

4 Comments

If you follow me on Twitter or have been following the rails core mailing list lately, you might have seen mention of the MetaWhere rewrite I’ve been working on. If you haven’t, let me start by linking you to the rewrite branch on GitHub. This is just a quick post explaining why I’m rewriting it, and why you should care.

Read the rest of this post

Filed under Blog
Feb 18, 2011

When to use alias_method_chain

15 Comments

Recently, I stumbled upon a fork of one of my projects in which someone made a really intelligent-sounding commit: “Remove needless indirection of alias_method_chain.” He used the term indirection, so I was duly impressed, and my curiosity was piqued: had I sinned against the programming gods and used an alias_method_chain when it wasn’t needed? No, I hadn’t. alias_method_chain is frequently abused in the Rails world, but it wouldn’t exist if there wasn’t a valid use case.
Read the rest of this post

Filed under Blog
Feb 3, 2011

attr_bucket, A Gem for Your Lolrus Model

5 Comments

Good evening, Internet! I hope you had a wonderful and productive workday. Now, with those pleasantries out of the way, I’d like to point you in the direction of a little gem called attr_bucket that I am regretful for having written even as I type this blog post suggesting you go try it. That is because this gem, while tiny and unassuming, has tremendous potential for evil.

Read the rest of this post

Filed under Blog
Jan 27, 2011

Current MetaWhere/MetaSearch Gems are RCs

1 Comment

Things have largely quieted down on the MetaSearch/MetaWhere front. The currently released gems are working well for me on a few large-ish projects, and I haven’t seen any serious bug reports in quite some time. I’m happy with the existing APIs, and while I’d certainly like to do a bit of refactoring, that’s nothing that should result in a breaking change. All this being said, I’m considering the latest releases of MW/MS as release candidates, and will be pushing out 1.0.0 of both relatively soon, barring any serious issues. Please get your bug reports in now!

Filed under Blog
Jan 13, 2011

Ruby 1.9, BasicObject, and ! (not)

2 Comments

In a recent discussion on the Rails-core mailing list, Joe Smith raised an issue that bothered me while I was working on my fork of Arel: predicate negation (not) has odd left-to-right readability. While only a minor annoyance, it did get me to spend some time tonight investigating a possible solution. This was when I got acquainted with Ruby 1.9′s BasicObject class, and more specifically, BasicObject#!.
Read the rest of this post

Filed under Blog
Apr 10, 2010

MetaSearch: Testers wanted

3 Comments

MetaSearch has had a bunch of nifty additions since the last released gem version. I’d really love to have some testers try out the new version, but it requires some handy additions to Arel which currently only exist on my fork. Those intrepid enough to try it out will gain a host of bug fixes, custom validators, and any- and all-suffixed methods for easier multi-condition searches.
Read the rest of this post

Filed under Blog
Apr 3, 2010

Advanced ActiveRecord 3 Queries with Arel

5 Comments

If you’ve been playing with Rails 3, you might not know that aside from the documented ways to construct your queries (chaining wheres with SQL fragments and hash conditions), there are some other nifty tricks waiting under the hood for you to discover.
Read the rest of this post

Filed under Blog
Mar 28, 2010

Easy Role-Based Authorization in Rails

30 Comments

Once user authentication has been added to your Rails app, authorization isn’t far behind. In fact, very basic authorization functionality exists the moment you implement user authentication. At that point, users who are logged in will have authorization to access areas of your application that others do not. The next common step is to add a boolean attribute to the User model to track whether a user is a "normal" user or someone who should have access to administer the application as well, yielding a convenient syntax like @user.admin?.

Adding an attribute to track a user’s administrator status may well be enough for a simple application, but at some point you will want something more flexible. After all, you don’t want to go adding a new column to your user table for every single possible authorization level, do you? Here’s one very easy way to handle things.
Read the rest of this post

Filed under Blog
Sep 30, 2008

Modifying Association Methods Dynamically

0 Comments

Recently, I encountered a bug in ActiveRecord’s AssociationCollection. When you push a new record into an associated collection, the collection in memory is always appended to, even if :uniq is set for the association. This causes a discrepancy in such a collection’s contents until a reload from the database removes the duplicates. While waiting for feedback on the patch I submitted, I wanted to fix the problem in my application. Now, I could have just redefined the AssociationCollection class during my app’s initialization, but that wouldn’t be very interesting. Since Rails associations are full of strange and wonderful magic, this posed a fun little coding exercise for a Saturday morning.
Read the rest of this post

Filed under Uncategorized
Aug 2, 2008

Updating MySQL DATETIMEs for Rails 2.1 Time Zones

6 Comments

So, if you haven’t heard, Rails 2.1 was released yesterday, And it comes chock full of time zoney goodness. But wait, don’t run off and enable time zone support in your app without reading this first!
Read the rest of this post

Filed under Uncategorized
Jun 2, 2008

About

I'm Ernie Miller. But then, you probably knew that by looking at the page title, or the URL. I'm a Ruby programmer in Louisville, Kentucky. This blog used to be called "metautonomo.us", which I thought was kind of clever, but nobody, including me, could type it. Lesson learned.