module ActiveRecord::ReadonlyAttributes::ClassMethods

def attr_readonly(*attributes)

post.update(title: "a different title") # raises ActiveRecord::ReadonlyAttributeError
post.title = "a different title" # raises ActiveRecord::ReadonlyAttributeError
post = Post.create!(title: "Introducing Ruby on Rails!")

end
attr_readonly :title
class Post < ActiveRecord::Base

==== Examples

not raise. The value will change in memory, but will not be persisted on +save+.
By setting +config.active_record.raise_on_assign_to_attr_readonly+ to +false+, it will

Assigning a new value to a readonly attribute on a persisted record raises an error.
Attributes listed as readonly will be used to create a new record.
def attr_readonly(*attributes)
  self._attr_readonly |= attributes.map(&:to_s)
  if ActiveRecord.raise_on_assign_to_attr_readonly
    include(HasReadonlyAttributes)
  end
end

def readonly_attribute?(name) # :nodoc:

:nodoc:
def readonly_attribute?(name) # :nodoc:
  _attr_readonly.include?(name)
end

def readonly_attributes

Returns an array of all the attributes that have been specified as readonly.
def readonly_attributes
  _attr_readonly
end