Class: Fields::Reference
- Inherits:
-
Field
- Object
- Field
- Fields::Reference
- Defined in:
- app/models/iron/fields/reference.rb
Instance Method Summary collapse
Instance Method Details
#content_value=(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/iron/fields/reference.rb', line 5 def content_value=(value) @content_errors = nil if value.blank? self.referenced_entry_id = nil return end referenced = Entry.find_by(id: value) if referenced.nil? add_content_error("must reference an existing entry") elsif !supported_content_type?(referenced) add_content_error("must reference a supported content type") else self.referenced_entry_id = value end end |
#export_value ⇒ Object
33 34 35 |
# File 'app/models/iron/fields/reference.rb', line 33 def export_value { type: "reference", value: referenced_entry_id } end |
#value ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/models/iron/fields/reference.rb', line 24 def value if referenced_entry.present? OpenStruct.new( id: referenced_entry_id, _type: referenced_entry.content_type.handle ) end end |