Fork me on GitHub



Qcontent is a growing collection of ruby modules and mix-ins for extending ActiveRecord. The mix-ins address a variety of common problems/features needed in Content Management Systems (CMS).


Over the past number of years of developing Ecommerce and CMS apps I found there was a lot of code that I was sharing between apps. The goal here was to extract the ActiveRecord extensions into shared modules, mix-ins, and macros so that they can be managed and maintained in a single place. These modules also go hand-in-hand with the ActionController/View extensions found in Qadmin.


Each module and mix-in has a different use which I’ll describe below, but the general idea is once installed in your Rails app, Qcontent modules can be included like:

class Article < ActiveRecord::Base
  include Qcontent::Published
  include Qcontent::Assets


The Published module gives a number of common methods for determining the published state of content in a CMS.

If you have a published_at column on your ActiveRecord class you automatically get:

# Article has a published_at :datetime column

# scope that only returns articles where published at is in the past

# returns the 3 most recent records ordered by published date

# published at is in the past

Article.published_only { #... } 
# with_scope

Event without a published_at column this can still be used. You just have to define a class method active_conditions. For example:

class Item < ActiveRecord::Base
  include Qcontent::Published
  # Item has no published_at but does have a boolean @active@ column
  def self.active_conditions
    {:active => true}

# Published gives you:
# named scope that uses the active conditions

Item.only_active {#...}
# with_scope that can be used in a @around_filter@ in ActionController


Dimension is a common class for extracting image/asset dimensions.

It can take a variety of inputs.

# these all return equivilent Dimension instances'100x100')[100, 100]){:width => 100, :height => 100})


Pricing extract the pattern of having Money objects stored on a model as an integer.

class Item < ActiveRecord::Base
  include Qcontent::Pricing
  # has column @retail_price_cents@ :integer
  has_price :retail_price, :default => nil
  # has column @wholesale@ :integer
  has_price :wholesale_price, :attribute => :wholesale

# this gives you automatic price conversions 
item = Item.first
#=> <Item>
item.retail_price = "$40"
#=> <Money @cents=4000>

item.retail_price = 40
#=> <Money @cents=40>

item.retail_price = '40.23'
#=> <Money @cents=4023>


There a bunch more mix-ins coming soon. Stay tuned! Watch the project on github for the latest updates.


  • rubygems >= 1.3.1
  • activesupport >= 2.2.0
  • activerecord >= 2.2.0
  • money >= 2.0


sudo gem install qcontent

Or directly from github:

sudo gem install quirkey-qcontent -s

Github in thier infinite awesomeness also lets you download the source in multiple formats.

Bugs/Feature Requests

The full and most up to date source is at github:

You can clone or fork from there to fix or break the code.

I’m happy to take feature requests/bug reports. Just email me (contact below) or message me on github.


This code is free to use under the terms of the MIT license.


Feel free to email me at aaron at quirkey dot com.

Please check out my blog.

If you like or use this library – I don’t want donations – but you can recommend me on or hire me to work on your next project.