模块:Mongoid::Attributes::Readonly

扩展方式:
ActiveSupport::Concern
包含在:
Mongoid::Attributes
定义于:
lib/mongoid/attributes/readonly.rb

Overview

此模块定义只读属性的行为。

在命名空间下定义

模块: 类方法

实例方法摘要折叠

实例方法详细信息

#attribute_writable? (name) ⇒ true | false

我们是否能够使用提供的名称写入属性?

例子:

我们可以写属性吗?

model.attribute_writable?(:title)

参数:

  • 名称 ( string | Symbol )

    字段的名称。

返回:

  • ( true | false )

    如果文档是新的,或者字段不是只读的。



25
26
27
# File 'lib/mongoid/attributes/readonly.rb', line 25

def attribute_writable?(名称)
  new_record? || (!self.class.readonly_attributes.包括?(名称) && _loaded?(名称))
end