Module: Gluttonberg::RecordHistory::ActionController::ControllerHelperClassMethods

Defined in:
lib/gluttonberg/record_history.rb

Overview

class methods

Instance Method Summary collapse

Instance Method Details

#log_createObject



30
31
32
33
34
35
36
37
# File 'lib/gluttonberg/record_history.rb', line 30

def log_create
  unless object.blank?
    if object.new_record?
    else
      Gluttonberg::Feed.log(current_user, object ,object_title , "created")
    end  
  end  
end

#log_destroyObject



47
48
49
50
51
# File 'lib/gluttonberg/record_history.rb', line 47

def log_destroy
  if object && object.destroyed?()
    Gluttonberg::Feed.log(current_user, object ,object_title , "deleted")
  end   
end

#log_updateObject



39
40
41
42
43
44
45
# File 'lib/gluttonberg/record_history.rb', line 39

def log_update
  unless object.blank?
    if object.errors.blank?
      Gluttonberg::Feed.log(current_user, object ,object_title , "updated")
    end  
  end  
end

#objectObject



53
54
55
56
57
# File 'lib/gluttonberg/record_history.rb', line 53

def object
  unless self.class.object_name.blank?
    self.instance_variable_get(self.class.object_name)
  end
end

#object_titleObject

this method is used to get title or name for the object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gluttonberg/record_history.rb', line 62

def object_title
  unless object.blank?
    field_name = ""
    if self.class.title_field_name.blank?
      if object.respond_to?(:name)
        field_name = :name
      elsif object.respond_to?(:title)
        field_name = :title
      elsif object.respond_to?(:title_or_name?)
        field_name = :title_or_name?
      else
        field_name = :id
      end
    else
      field_name = self.class.title_field_name     
    end
    puts "====================  field_name  #{field_name}"
    unless field_name.blank?
      object.send(field_name)
    end
  end  
end