Sha256: fbd97727c9adf6e127e174659d9671193fb0c809a991483eecec322697c80df3

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents


class ActiveRecord::Base
  extend ModelMixins::TableBuilderClassMethods
end

module ApplicationHelper
  include ViewMixins::Link
  include ViewMixins::Form
  include ViewMixins::Breadcrumb
  include ViewMixins::Table
end

class ApplicationController
  include ControllerMixins::RendererInstanceMethods
end


# monkey patch for control of right timestamp when updating a model, in the case that somebody updatedd it in the time beetween show the form and update the form
# it will yell it was updated by another user
module ActiveRecord
  # = Active Record Persistence
  module Persistence

    def update_attributes(attributes, options = {})
      if timestamp_control = attributes.delete(:control_against_overwrite_by_another_user)
        if self.attributes['updated_at'] > timestamp_control
          errors[:base] << I18n.t('activerecord.errors.messages.control_against_overwrite_by_another_user')
          return false
        end
      end
      with_transaction_returning_status do
        self.assign_attributes(attributes, options)
        save
      end
    end

    def update_attributes!(attributes, options = {})
      if timestamp_control = attributes.delete(:control_against_overwrite_by_another_user)
        if self.attributes['updated_at'] > timestamp_control
          errors[:base] << I18n.t('activerecord.errors.messages.control_against_overwrite_by_another_user')
          return false
        end
      end
      with_transaction_returning_status do
        self.assign_attributes(attributes, options)
        save!
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
it-logica-application-backbone-0.1.7 lib/initializers/initialize.rb