Ernie Miller

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

RSS Feed

Tag Archives: coding

SimpleSearch, searching ActiveRecord Objects with form_for

0 Comments

About 2 years ago, I made a basic how-to post on building a search model that could be used with form_for. I still really enjoy this basic pattern for search forms, but it always seemed like most of the gems I found relating to search were far more involved than I need, providing integration with fulltext search engines, and so on.
Read the rest of this post

Filed under Blog
Feb 24, 2010

What I’ve been up to, and a few plugs

0 Comments

So I’ve been really silent on here for quite some time, but I’ve been very busy. Despite the long period of inactivity, the blog continues to get quite a few hits, so I thought it time to update everyone on what’s been happening.
Read the rest of this post

Filed under Blog
Feb 23, 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

PHP: A Bridge Too Many?

2 Comments

Development language preferences are funny things. I’m well aware of the benefits that come from being familiar with many languages, not least of which is the perspective needed to discern the right tool for each job. As they say, when the only tool you have is a hammer, everything looks like a nail. I’ve had exposure (in varying degrees) to a fair number of programming languages in my time: BASIC, Pascal, Ada, C, Bourne Shell, Perl, Python, PHP, Java, Javascript, VB, and Ruby among them, so I feel as though I do have some general ideas about the kinds of features I look for in a language.

All that being said, there are some tools that I can’t help but wonder about. PHP is one of them.
Read the rest of this post

Filed under Blog
Aug 20, 2008

Today, you’re as dumb as you’ll ever be.

0 Comments

If you’ve been coding for a while, particularly if you spend much time with the agile development crowd, you’ve probably heard the term YAGNI, or “You Ain’t Gonna Need It.” Simply put, this principle states that we shouldn’t spend time adding features or flexibility that you don’t need right now, because it’s likely that you ain’t gonna need it later, either. I recently purchased Russ Olsen’s excellent book, Design Patterns in Ruby, in which he makes one of the most eloquent and succinct arguments for YAGNI I’ve yet seen.
Read the rest of this post

Filed under Blog
Aug 19, 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

The local_request That Isn’t

1 Comment

If your Rails application’s primary users are on your company’s intranet, and you host your app using mongrel_cluster and Apache’s mod_proxy_balancer or something similar, you may have noticed a potentially unwanted side effect: users who cause exceptions in your application will get a stack trace instead of your configured error page, even when running in production mode. This is a good excuse to peek into the Rails internals and explain how Rails determines what page to display when it encounters an error.
Read the rest of this post

Filed under Uncategorized
May 30, 2008

Importing Legacy Data to Your Rails Database

1 Comment

A while back, I faced the need to migrate some old data out of a simple web application done by another group within my company. The app was designed on the quick, and basically just dumped all input into one table, without much (any?) sanity-checking. As I sat down with my trusty text editor, ready to whip out a few lines of Perl as I’d done so many times before to quickly scrub and load this data into its appropriate place within its new home, it occurred to me that I was just about to reimplement a bunch of validations and transformations I’d already taken care of once in Ruby. Yes, I had temporarily taken leave of my senses. There had to be a better way, and there was.
Read the rest of this post

Filed under Uncategorized
May 2, 2008

Simplified Active Directory User Authentication

4 Comments

A central source for user authentication is a worthwhile thing for a company to have. Unfortunately, for much of the corporate world, this means Microsoft Active Directory. Hey, it’s not all bad. At least Ruby applications can access Active Directory with the ruby-net-ldap gem. Still, code in a Rails application which has to deal with LDAP attributes can look downright foreign next to all of your nifty English-looking attribute names, and ActiveLdap, while very cool, is overkill for simple tasks. Sometimes you just want a simple way to get at a few key attributes about your users once they log in. Maybe you’re looking to cache that info in a local database table so that you can enforce database integrity checks, for instance? Here’s a single file you can just drop into your Rails (or plain old Ruby) project and use any way you see fit.
Read the rest of this post

Filed under Uncategorized
Apr 4, 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.