acts_as_formatted 0.1 is out

Ruby on Rails, Software development Add comments

I was doing a little Ruby on Rails hacking and I needed an easy way to automatically format ActiveRecord string columns. I was surprised that this wasn’t built into Rails already, and even more when I couldn’t find a 3rd party plugin that did that. I guess the open source community was calling on me to write my own!

I’m glad to introduce acts_as_formatted 0.1. Here’s an example of how it works. As you can see, it is pretty straightforward:

class Person < ActiveRecord::Base
acts_as_formatted :case => :capitalize, :except => :suffix
end

This snippet formats all string fields by Capitalizing the first letter of a string, and by stripping leading and trailing white spaces. No more custom setters. acts_as_formatted can also change the case to UPPERCASE, lowercase or sWAP cASE. Check out the README for more details on usage and installation instructions. Comments are welcome, of course!

2 Responses to “acts_as_formatted 0.1 is out”

  1. joey Says:

    I’m an extreme newbie, but isnt this built in to the Ruby string class itself?

  2. Carl Says:

    The formatting is indeed built in the String class, but this plugin adds automatic formatting to ActiveRecord string columns, which is different. There was no way to automate this before.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in