By Tim Lucas

Building blocks for a CMS

By Tim Lucas
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

Though there’s been a few attempts at creating high-level, pluggable components in Rails, nothing has really seemed to catch on. There’s Rails engines and some full-blown CMS packages, but there’s still a tendency to built things from the ground up. Why is this?

I’ll list a few low-level tools that you can integrate into any project, that don’t mess with Rails internals and are dead-easy to set up and use.

  • acts_as_tree or acts_as_nested_set

    Built into Rails, these will give you a tree model for any model objects. Sprinkle on LiveTree for a Javascript-based UI.

  • acts_as_versioned

    Store previous copies of Pages, Assets or any danged model that you please.

  • acts_as_versioned_association

    Building on top of acts_as_versioned, this provides versioning support for your associations, so if you had a Page that had associated ImageAssets you could retrieve an exact copy of your page along with the associated image assets at that point in time.

  • Polymorphic associations

    Built into Rails 1.1, polymorphic associations allow you to associate a model with any other type of model through a polymorphic join association. This means you could tack a Comment onto any of your model objects, like in the following example:

    class Comment < ActiveRecord::Base
      belongs_to :commentable, :polymorphic => true

    Adding comment support to a model is simply a matter of inserting a has_many one-liner:

    class Post < ActiveRecord::Base
      has_many :comments, :as => :commentable
  • acts_as_attachment

    Provides both file and DB-based upload storage, as well has ImageMagick support for auto-resizing of images. If this isn’t flexible enough there’s the more image-manipulation-based ImageMagick for Rails plugin.

What other building blocks have you used when adding typically CMS-like features to your Rails application?

Login or Create Account to Comment
Login Create Account
Get the most important and interesting stories in tech. Straight to your inbox, daily.Is it good?