Agile Web Development

Build it. Launch it. Love it.

validates_as_readonly

validates_as_readonly adds validations for ensuring that certain ActiveRecord attributes are not written to.

Resources

Announcement

Wiki

API

Development

Source

Description

Sometimes there are certain attributes in your ActiveRecord models that should never be modified after being saved to the database for the first time or while the model is in a certain state. It’s difficult to ensure the integrity of your models without such validations. validates_as_readonly helps to verify that your models remain in a consistent state and do not get unexpectedly written to.

Usage

See the API for usage information and examples.

Testing

Before you can run any tests, the following gems must be installed:

Dependencies

This plugin does not depend on the presence of any other plugin.

Vitals

Home http://wiki.pluginaweek.org/Validates_as_readonly
Repository http://svn.pluginaweek.org/trunk/plugins/active_record/validations/validates_as_readonly
License Rails' (MIT)
Rating (0 votes)
Owner Aaron Pfeifer, Neil Abraham
Created 5 October 2007

Comments

  • Avatar
    Felipe Giotto
    6 October 2007

    I've been looking for a plugin like this for days!! Now we'll finally finish our scary ToDo item n° 2!!

  • Avatar
    Peter Boling
    11 October 2007

    Would be nice if it worked!
    doing this:
    class Status < ActiveRecord::Base
    validates_as_readonly :cd
    end

    gives me this in the log:
    NoMethodError (You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.+):
    /rails_app/vendor/plugins/validates_as_readonly/lib/validates_as_readonly.rb:123:in `readonly_attributes'
    /rails_app/vendor/plugins/validates_as_readonly/lib/validates_as_readonly.rb:140:in `readonly_attribute?'
    /rails_app/vendor/plugins/validates_as_readonly/lib/validates_as_readonly.rb:152:in `write_attribute'

  • Avatar
    24 October 2007

    May I suggest an alternative that is bug-free? ;-)

    Validates Constancy is a Rails plugin and a RubyGem. Check it out.

Add a comment