Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Nov 19, 2009

Acts As Lockdown

A Rails plugin that addresses the need for certain ActiveRecord attributes to be unwritable when a record has entered a certain state. Take for example a product that begins in a “pending” state, and later enters a “published” state. From that point on, you require that the price and description must not be changed.

The plugin assumes that you have a state machine in place that and your object will respond to a query on the state you specify eg self.published? It works by overwriting the setters. The getters remain unchanged.

Usage

Include acts_as_lockdown, then do a lockdown specifying the state, and any fields that you want frozen from further writing.

class Product

Download

Get it here: http://github.com/gordonbisnor/acts_as_lockdown


I am available for Ruby on Rails consulting work – get in touch to learn more.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus