Blog (rails)

@fredwu 14 years ago | 1 min read | no comments
If you don’t already know, ’delayed_job’ is a database based asynchronously priority queue system extracted from Shopify. I was seeking for a lightweight, easy to use solution for queueing tasks, ‘delayed_job’ fits the bill almost perfectly. ;) One thing we needed to do for a Rails 2 project at Envato, was to queue the tasks and to run them one after another, at a set interval. 'delayed_job’ unfortunately doesn’t come with this feature. So, instead of searching for more complicated solutions o...
@fredwu 14 years ago | 1 min read | no comments
Rails 3 has recently renamed key method to to_key, which consequently rendered MongoMapper unusable. You might see an error that looks like: ActionView::Template::Error (undefined method `to_key' for #<Post:0x000001066e4020>) After some twiddling I’ve submitted a patch to address this issue. Feel free to pull my fork until the fix makes its way into John Nunemaker’s main repository.
@fredwu 14 years ago | 2 min read | no comments
Web applications normally have many forms. Building forms is always a mind-boggling task because it involves repetition and chaos. A shortcut is to use a form builder / DSL, such as Formtastic. As I am using Rails 3, and the Rails 3 port of Formtastic isn’t complete yet, I thought I’d just use the plain vanilla Rails built-in form helper. First of all, I am using Haml instead of ERb. Already, I got the out-of-box clean looking Haml markup. Some of you might not be aware of the fact that Rails...
@fredwu 14 years ago | 1 min read | no comments
So we want to dynamically instantiate an object (i.e. convert a string to a class constant). Instead of doing this: @dynamic_var = "User" eval(@dynamic_var) You can do this: @dynamic_var = "User" @dynamic_var.constantize See more about the constantize method in Rails’s API.