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
35 36 37 |
# File 'app/models/iron/fields/reference.rb', line 35 def export_value { type: "reference", value: referenced_entry_id } end |
#filled? ⇒ Boolean
24 |
# File 'app/models/iron/fields/reference.rb', line 24 def filled? = referenced_entry_id.present? |
#value ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/models/iron/fields/reference.rb', line 26 def value if referenced_entry.present? OpenStruct.new( id: referenced_entry_id, _type: referenced_entry.content_type.handle ) end end |