From 3289d0a7a0589baa5bff470df4e07ec2bed99222 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 7 Feb 2009 23:36:57 +0100 Subject: added draft method to node model --- app/models/node.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/models/node.rb b/app/models/node.rb index e08e228..4e865e3 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -33,6 +33,22 @@ class Node < ActiveRecord::Base # Instance Methods + def draft + + # check if there is a page which has a nil :published_at column + # if there is one - it is considered a draft else a new revision is + # created + + if draft = pages.find_by_published_at(nil) + draft + else + # make a new fresh page with node reference + draft = Page.new( :node_id => id) + end + + draft + end + # returns an array with all parts of a unique_name rather than a string def unique_path unique_name.split("/") rescue unique_name -- cgit v1.3