Topic: How do you handle draft versions of models?

Let's say you have a model called Article.  You want to validate the article, but only if the person is actually trying to publish it.  The validations shouldn't run when the article is in draft format.  Is there a clean way to handle this using ActiveRecord validations or do I need to write my own custom method to handle this type of validation?

Re: How do you handle draft versions of models?

You can use the :if condition on validations to only call them in certain cases:

class Article < ActiveRecord::Base
  validates_presence_of :title, :if => :publishing?
 
  def publishing?
    # returns true or false depending on whether this article is being published
  end
end

Railscasts - Free Ruby on Rails Screencasts