Module: UserActivities

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/user_activities.rb

Overview

User Activities methods Methods related to cloudobject/activities and user_logs

Instance Method Summary collapse

Instance Method Details

#log(description, session = nil) ⇒ void

This method returns an undefined value.

Parameters:

  • description

    String Details about the process

  • session (defaults to: nil)

    String Current or active session id



44
45
46
# File 'app/models/concerns/user_activities.rb', line 44

def log description, session=nil
    self.logs.create(session, description)
end

#log_activity_update(current_user, user, old_attributes, new_attributes) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/concerns/user_activities.rb', line 48

def log_activity_update(current_user, user, old_attributes, new_attributes)
    old_attributes.except!("id", "users_id", "created_at", "updated_at", "deleted_at")
    old_attributes.each do |key, value|
        if value != new_attributes[key]
            value_from = value
            value_to = new_attributes[key]
            value_from = Courier::Core::Date.to_string_datetime(value_from) if value_from.is_a?(Time) || value_from.is_a?(Date)
            value_to = Courier::Core::Date.to_string_datetime(value_to) if value_to.is_a?(Time) || value_to.is_a?(Date)

            user.activities.create!(
                assigned: current_user,
                category: "action_update",
                field_name: key,
                value_from: value_from,
                value_to: value_to
            )
        end
    end
end