app/models/activeadmin_selleo_cms/section.rb in activeadmin-selleo-cms-0.0.18 vs app/models/activeadmin_selleo_cms/section.rb in activeadmin-selleo-cms-0.0.20
- old
+ new
@@ -6,10 +6,12 @@
attr_protected :id
belongs_to :sectionable, polymorphic: true
+ delegate :layout, to: :sectionable
+
accepts_nested_attributes_for :translations
validates_presence_of :name
validates_uniqueness_of :name, scope: [:sectionable_type, :sectionable_id]
validates_associated :translations
@@ -24,14 +26,44 @@
when /help\./ then "Lite"
else "Easy"
end
end
+ def image
+ if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.image}
+ current_translation.image
+ else
+ nil
+ end
+ end
+
+ def attachment
+ if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.attachment}
+ current_translation.attachment
+ else
+ nil
+ end
+ end
+
+ def images
+ if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.images.any? }
+ current_translation.images
+ else
+ []
+ end
+ end
+
class Translation
attr_protected :id
has_many :attachments, as: :assetable
+ has_many :images, as: :assetable
+ has_one :attachment, as: :assetable
+ has_one :image, as: :assetable
- accepts_nested_attributes_for :attachments
+ accepts_nested_attributes_for :attachments, reject_if: lambda{ |i| i[:data].blank? }
+ accepts_nested_attributes_for :attachment, reject_if: lambda{ |i| i[:data].blank? }
+ accepts_nested_attributes_for :image, reject_if: lambda{ |i| i[:data].blank? }
+ accepts_nested_attributes_for :images, reject_if: lambda{ |i| i[:data].blank? }
end
end
end