All Futures
  • All Futures
  • Setup
  • Usage
    • Active Record
    • Attributes
    • Associations
    • Aggressions
    • Callbacks
    • Dirty
    • Errors
    • Readonly
    • Validations
    • Versioning
  • API Reference
    • Class Methods
    • Instance Methods
    • Getter Methods
    • Overwritable Methods
  • Examples
    • Faceted Search
Powered by GitBook
On this page

Was this helpful?

  1. Usage

Readonly

You can use attr_readonly :title, :author to prevent assign value to attribute after initialized.

You can use enable_readonly! and disable_readonly! to control the behavior.

Important: It's no effect with embeds or array attributes !!!

enable_attr_readonly!, disable_attr_readonly!

attr_readonly_enabled?

without_attr_readonly(&blk)

readonly_attribute?(attribute)

readonly!, readonly?

Mark the current model instance as readonly, which prevents any future attempts to save or update. The instance is still accessible, just frozen.

The transition to readonly, is one-directional and cannot be reversed. If you need to write to this instance again, you'll have to find it again. This is different from marking an individual attribute as readonly, which can be reversed.

Class methods

readonly_attributes

Returns a Set of attributes that are marked with attr_readonly in your All Futures class. Attributes in the Set are presented as Strings.

PreviousErrorsNextValidations

Last updated 3 years ago

Was this helpful?