Readonly ActiveRecord Columns
ActiveRecord doesn't have a built in means of labeling a column readonly. The best way to work around this is to setup an on update validation like so:
validate :message_cannot_change, on: :update
def message_cannot_change
if self.message_changed?
errors.add(:message, "must not change")
end
end
This will mark the "message" column as readonly. Obviously, you can change that name to whatever column name you would like.
Written by Sean Todd
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#