Sha256: 4f02b86f93606900cc532a775618397ea4de51b4938067d63d2f361e389715b9

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module Refinery
  module Contacts
    module Extensions
      module Pages
        def has_one_contact
          has_one :contact_page, :as => :page, :dependent=> :destroy
          has_one :contact, :through => :contact_page
          has_many :mails, :class_name => Refinery::Contacts::Mail, :through => :contact


          accepts_nested_attributes_for :contact_page

          module_eval do
            def contact_page=(contact_page_params)
              # new
              if self.contact_page.nil?
                self.build_contact_page
              end

              # destroy
              if contact_page_params[:contact_id].blank?
                self.contact_page.destroy

              # create or update if changed
              elsif (self.contact_page.contact_id.to_s != contact_page_params[:contact_id]) || (self.contact_page.contact_info != contact_page_params[:contact_info] )
                self.contact_page.update_attributes( contact_page_params)
                self.contact_page.save
              end

            end
          end

        end
      end
    end
  end
end

ActiveRecord::Base.send(:extend, Refinery::Contacts::Extensions::Pages)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
refinerycms-contacts-0.2.0 lib/refinery/contacts/extensions/pages_extension.rb