Links
validates_as_readonly
Categories
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:
- plugin_test_helper[http://wiki.pluginaweek.org/Plugin_test_helper]
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
-
I've been looking for a plugin like this for days!! Now we'll finally finish our scary ToDo item n° 2!!
-
Would be nice if it worked!
doing this:
class Status < ActiveRecord::Base
validates_as_readonly :cd
endgives 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' -
May I suggest an alternative that is bug-free? ;-)
Validates Constancy is a Rails plugin and a RubyGem. Check it out.
