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
32
33
# 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
  ).order('created_at ASC')
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



35
36
37
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 35

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

.resource_type(resource) ⇒ String

Returns The name of the record to use for the polymorphic relationship

Returns:

  • (String)

    The name of the record to use for the polymorphic relationship



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



39
40
41
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 39

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