Class: CustomerPj
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CustomerPj
- Defined in:
- app/models/customer_pj.rb
Instance Method Summary collapse
- #associate_to!(customer_pj) ⇒ Object
-
#existing_customer_segment_attributes=(segment_attributes) ⇒ Object
after_update :save_customer_segments.
- #name ⇒ Object
-
#new_customer_segments_attributes=(segment_attributes) ⇒ Object
many-to-many helpers <———————————–.
- #prefix ⇒ Object
- #save_customer_segments ⇒ Object
Instance Method Details
#associate_to!(customer_pj) ⇒ Object
63 64 65 |
# File 'app/models/customer_pj.rb', line 63 def associate_to!(customer_pj) associations.create!(to: customer_pj) end |
#existing_customer_segment_attributes=(segment_attributes) ⇒ Object
after_update :save_customer_segments
39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/customer_pj.rb', line 39 def existing_customer_segment_attributes=(segment_attributes) segments.reject(&:new_record?).each do |segment| attributes = segment_attributes[segment.id.to_s] if attributes segment.attributes = attributes else segment.delete(segment) end end end |
#name ⇒ Object
67 68 69 |
# File 'app/models/customer_pj.rb', line 67 def name customer.name end |
#new_customer_segments_attributes=(segment_attributes) ⇒ Object
many-to-many helpers <———————————–
31 32 33 34 35 |
# File 'app/models/customer_pj.rb', line 31 def new_customer_segments_attributes=(segment_attributes) segment_attributes.each do |attributes| segments.build(attributes) end end |
#prefix ⇒ Object
59 60 61 |
# File 'app/models/customer_pj.rb', line 59 def prefix "pj" end |
#save_customer_segments ⇒ Object
50 51 52 53 54 |
# File 'app/models/customer_pj.rb', line 50 def save_customer_segments segments.each do |segment| segment.save(false) end end |