Sha256: 607f5f42b014bb5d86ab4f37daab2d5202f15b44d8dc1ce76f9c56172497fcbf

Contents?: true

Size: 1.53 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

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