Sha256: a7e8b2c4d8006457082e6b32e92b5c5dfc2a17668524d16fe3a0b958c6da088a

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

require 'refinery'

module Refinery
  module PageImages
    class Engine < Rails::Engine
      initializer "static assets" do |app|
        app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
      end

      config.to_prepare do
        Page.module_eval do
          has_many :image_pages
          has_many :images, :through => :image_pages, :order => 'position ASC'
          # accepts_nested_attributes_for MUST come before def images_attributes=
          # this is because images_attributes= overrides accepts_nested_attributes_for.
          accepts_nested_attributes_for :images, :allow_destroy => false

          def images_attributes=(data)
            self.images.clear
            self.images += (0..(data.length-1)).collect { |i|
              (Image.find(data[i.to_s]['id'].to_i) rescue nil)
            }.compact
          end
        end
      end

      config.after_initialize do
        Refinery::Pages::Tab.register do |tab|
          tab.name = "images"
          tab.partial = "/admin/pages/tabs/images"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
refinerycms-page-images-0.9.8 lib/refinerycms-page-images.rb
refinerycms-page-images-0.9.7 lib/refinerycms-page-images.rb
refinerycms-page-images-0.9.6 lib/refinerycms-page-images.rb