I’m working on a system for managing multiple different items, let’s say
articles and pictures. All these items can be published and unpublished.
They have a published_at datetime field that is nil in unpublished
state, and filled out in published state.
This is the code that I use in the models:
class SomeModel < ActiveRecord::Base
!published? || Time.now < published_at
pending? ? :pending : :published
self.published_at = Time.now if self.pending?
self.published_at = nil
But, I want to keep it DRY, and I do not want to add these lines to any
model that should be publishable. I tried to create a
publishable_item.rb model class and to inherit from that, but in this
case Rails will look for a publishable_items table.
So I’m looking forward to your suggestions.