Module: Parted
- Included in:
- GuideEdition, ProgrammeEdition, TravelAdviceEdition
- Defined in:
- app/models/parted.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
4 5 6 7 8 |
# File 'app/models/parted.rb', line 4 def self.included(klass) klass. :parts klass.accepts_nested_attributes_for :parts, allow_destroy: true, reject_if: proc { |attrs| attrs["title"].blank? and attrs["body"].blank? } end |
Instance Method Details
#build_clone(edition_class = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/parted.rb', line 10 def build_clone(edition_class=nil) new_edition = super # If the new edition is of the same type or another type that has parts, # copy over the parts from this edition if edition_class.nil? or edition_class.include? Parted new_edition.parts = self.parts.map {|p| p.dup } end new_edition end |
#order_parts ⇒ Object
22 23 24 25 26 27 |
# File 'app/models/parted.rb', line 22 def order_parts ordered_parts = parts.sort_by { |p| p.order ? p.order : 99999 } ordered_parts.each_with_index do |obj, i| obj.order = i + 1 end end |
#whole_body ⇒ Object
29 30 31 |
# File 'app/models/parted.rb', line 29 def whole_body self.parts.map {|i| %Q{\# #{i.title}\n\n#{i.body}} }.join("\n\n") end |