Using I18n and Draper to Render Database Attributes
TL;DR;: Check out my additions to ApplicationDecorator in this gist.
When my models have an attribute that matters to the code (like Admin#role or User#status),
I like to store the value as a string that makes sense as an identifier.
For example, User#status might be ‘active’ or ‘awaiting_approval’.
However, when it comes time to render the admin’s role or the users status in the view,
we want to show ‘Awaiting approval’ instead of ‘awaiting_approval’.
Another example of this sort of thing is the #type attribute for STI.
Ok, this isn’t too hard, we can just use #humanize. But, here’s what happens:
Read More
I Can Haz Disqus
I’ve added comments to this blog. So, if you wanted to comment on my posts, now you can!
How to get GetBundles working with RVM
Ever since I set rvm to use ruby 1.9.2 as my default, GetBundles hasn’t been working.
A quick peek at TextMateGetBundles.log revealed that there were syntax errors in Support/getBundles.rb. Here’s what I did to make GetBundles use ruby 1.8.7
This is how I got GetBundles to work with rvm.
Read More
Do you practice specific skills with repetition and intent? Athletes do drills. Musicians hone difficult passages. What do you do?
Delete action in Rails 3
At Carnes Media, we’ve been really happy with using a delete action as a confirmation step before calling destroy.
This solves a bunch of problems:
- No more hacky inline javascripts that create a DELETE form.
- We render the delete form in a modal instead of a confirm dialog.
- It’s a completely unobtrusive solution and easy to test with cucumber.
Here are a couple of bits and pieces that help make this pattern easier:
Read More
Konami jQuery Plugin
Back when I worked at Tatango, Adrian wrote a very concise implementation for the konami code.
So, I figured I would make a nice little jQuery plugin. This is how you would use it:
Read More
A Couple of Handy Cucumber Transforms
I’m writing some cucumber tests for a billing system, and I figured I’d try cucumber transforms for parsing CreditCard and Money object out of steps. Here’s what I came up with:
If we accept that code is design — a creative process rather than a mechanical one — the software crisis is explained. We now have a design crisis: The demand for quality, validated designs exceeds our capacity to create them. The pressure to use incomplete design is strong.
Another jQuery plugin
A friend recently was asking about scoping a bunch of jquery calls to a particular container. So… I wrote this plugin: http://github.com/amiel/jquery_scope
Here are some contrived usage examples: