Class: Binda::Component
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Binda::Component
- Extended by:
- FriendlyId
- Includes:
- AASM, FieldableAssociations
- Defined in:
- app/models/binda/component.rb
Class Method Summary collapse
- .remove_orphans ⇒ Object
-
.sort_limit ⇒ Object
The limit above which componets cannot be sorted anymore.
Instance Method Summary collapse
-
#create_field_instances ⇒ Object
Create field instances for the current component.
-
#should_generate_new_friendly_id? ⇒ Boolean
Friendly id preference on slug generation.
Methods included from FieldableAssociations
#find_or_create_a_field_by, #generate_fields
Class Method Details
.remove_orphans ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/models/binda/component.rb', line 65 def self.remove_orphans Component .includes(:structure) .where(binda_structures: {id: nil}) .each do |c| c.destroy! puts "Binda::Component with id ##{c.id} successfully destroyed" end end |
.sort_limit ⇒ Object
The limit above which componets cannot be sorted anymore
51 52 53 |
# File 'app/models/binda/component.rb', line 51 def self.sort_limit 1000 end |
Instance Method Details
#create_field_instances ⇒ Object
Create field instances for the current component
56 57 58 59 60 61 62 63 |
# File 'app/models/binda/component.rb', line 56 def create_field_instances instance_field_settings = FieldSetting .includes(field_group: [ :structure ]) .where(binda_structures: { id: self.structure.id }) instance_field_settings.each do |field_setting| field_setting.create_field_instance_for(self) end end |
#should_generate_new_friendly_id? ⇒ Boolean
Friendly id preference on slug generation
Method inherited from friendly id
46 47 48 |
# File 'app/models/binda/component.rb', line 46 def should_generate_new_friendly_id? slug.blank? end |