Method: Scrivito::AttributeContent::ClassMethods#attribute
- Defined in:
- app/cms/scrivito/attribute_content.rb
#attribute(name, type, options = {}) ⇒ Object
Defines an attribute.
For the purpose of persisting model data in the CMS, the attributes of the model need to be defined. When defining an attribute, you specify the name under which Scrivito should persist its value as well as the type of content it is meant to contain, and, for the enum
and multienum
types, the selectable values.
Attributes are inherited. If, for example, the Page
model defines a title
attribute of the string
type, the SpecialPage
model, which inherits from Page
, is also equipped with title
. Inherited attributes can be overridden, i.e. you may redefine title
in SpecialPage
if you want its type to be html
, for example.
459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'app/cms/scrivito/attribute_content.rb', line 459 def attribute(name, type, = {}) name, type, = name.to_s, type.to_s, assert_valid_attribute_name(name) assert_valid_attribute_type(type) default = .delete(:default) || .delete('default') if default assert_valid_attribute_default(name, type, default) default_for(name) { default } end own_attribute_definitions[name] = AttributeDefinition.new(name, type, ) nil end |