Topic: App design q: Implementing 'Published' attribute and preview mode


I'd like to extend a simple cms that i'm working on. I'd like users of the cms to be able to add items without them immediately showing up on the public part of the site and I also want the logged-in cms user to be able to view a 'preview' version of the site that _does_ include unpublished items.

My plan is to use a plugin like acts_as_activated to add boolean 'active' attributes to some models (eg. news_item, blog_post).

This plugin works by overriding the find methods for the models it's applied to to only return results whose 'active' attributes are set to true. The plugin also provides a 'find_with_inactive' method to return all records.

What i'm stumped with is how to implement the preview mode.

My initial thoughts are that i would store a preview mode boolean switch as a session variable, and then somehow use that switch to determine (for all acts_as_active models) whether to use their original 'find' methods, or the new version of the methods that exclude inactive records.

I can't seem to think of a sensible way to do this.

(maybe i could create an 'acts_as_previewable' plugin and use that to check for the presence of the preview mode session variable, but even if this is possible it seems wrong to be checking application state inside a model..)

Thanks in advance for any suggestions or pointers.