Class: ActiveAdmin::Comment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_admin/orm/active_record/comments/comment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_for_resource_in_namespace(resource, namespace) ⇒ Object



27
28
29
30
31
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 27

def self.find_for_resource_in_namespace(resource, namespace)
  where resource_type: resource_type(resource),
        resource_id:   resource_id_cast(resource),
        namespace:     namespace.to_s
end

.resource_id_cast(record) ⇒ Object

Postgres adapters won't compare strings to numbers (issue 34)



23
24
25
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 23

def self.resource_id_cast(record)
  resource_id_type == :string ? record.id.to_s : record.id
end

.resource_id_typeObject



33
34
35
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 33

def self.resource_id_type
  columns.detect{ |i| i.name == "resource_id" }.type
end

.resource_type(resource) ⇒ Object



18
19
20
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 18

def self.resource_type(resource)
  ResourceController::Decorators.undecorate(resource).class.name.to_s
end

Instance Method Details

#set_resource_typeObject



37
38
39
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 37

def set_resource_type
  self.resource_type = self.class.resource_type(resource)
end