method

readonly?

Importance_1
v1.0.0 - Show latest stable - 1 note - Class: ActiveRecord::Base
readonly?() public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Show source
Register or log in to add new notes.
October 2, 2009
2 thanks

Making ActiveRecord models readonly

To force an ActiveRecord model to be read only you can do something along these lines:

class DelicateInfo < ActiveRecord::Base

 def readonly?
  true
 end

end

When you try to save the model it will raise an ActiveRecord::ReadOnlyRecord exception:

info = DelicateInfo.first
info.save # => ActiveRecord::ReadOnlyRecord

Note, however, that destroy and delete will still work on the model unless you intercept those calls