On a couple of Android projects I’m working on, I’ve switched to using the new Gradle Build system. The idea of storing the entire build configuration in one place is great.
I recently discovered the excellent ActiveRecord
store method whilst researching the best-practice for storing optional, flexible metadata against a record.
store lets you keep simple key/value data into a single text column on your model.
Every time I start a new Rails 3 project, I’m always caught out by its autoloading behaviour. Rails 3 will only require (and so autoload) a module when it is first encountered within the application code, for example by a call to
If you like to test out the latest and greatest builds of Ubuntu, you might like to try the latest 11.04 beta in VirtualBox.
In previous posts, I wrote how to build complex search queries in Rails 2 using the ez_where plugin. In Rails 3, such plugins and long-winded code is completely unnecessary thanks to the powerful ActiveRelation query interface.
In developing the next phase of markstocks.com, I needed to simulate a file upload attribute in my FactoryGirl factories. A quick Google revealed some promising code, but everything out there was based on Rails 2.
Default scopes were introduced in Rails 2.3 to allow a default set of options to be applied to any find methods. The common example is to always order a set of results by a given column, e.g:
Plugins are great in Rails, but sometimes they seem a bit much for certain tasks, such as writing a quick utility mixin. In a previous post on writing DRY validators, I discussed putting the validation mixin code inside Rails’
I’ve been using the acts_as_revisable plugin in my Rails apps to store a revision history of ActiveRecord models. The plugin automatically versions your models, and allows you to navigate revisions; branch and merge changes, and perform bulk changesets.
I recently upgraded a project from Rails 2.3.2 to 2.3.3, after which I started getting strange the following error from Passenger:
Update 28 June 2009: Rollo Tomazzi noted in the comments that the method described below will not work for hash-value attributes. He has written a review of the various methods for setting default attribute values on his blog.
I recently spent not an insignificant amount of time trying to get my unit tests to comply with Rails’ single-table inheritance. Single table inheritance allows you to map a hierarchy of classes to a single table in the database, so from one user table I can have an Employee and a Manager. They both inherit from a User model in Rails, and are stored in the users database table. A manager, though, might have more properties (fields) and methods than an Employee, which can be defined in manager.rb:
I am currently using rsync as a backup solution between two computers and an external backup drive, all operating across my wireless LAN. However, every so often - and always when syncing a lot of files - rsync has knocked out my wireless internet. Today, I decided to find out what was going on, and found the solution:
Like quite a few others, I was pleased to hear thatÂ GoogleÂ has finally got round toÂ adding IMAP to its GMailÂ service. IMAP means checking and dealing with emails from multiple sources is a lot simpler, as any changes are synchronised back to the server. I patiently waited for the IMAP tab to appear in my settings panel, as Google had announced it would take a few days to activate. After a couple of days, though, I began to wonder if they had forgotten about my one lonely GMail account, and starting browsing theÂ help pages for any hint of what might be happening. By sheer luck,Â I happened upon this little nugget of info: