Class: ActiveAdmin::Comment

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

Class Method Summary collapse

Class Method Details

.find_for_resource_in_namespace(resource, namespace) ⇒ Object



32
33
34
35
36
# File 'lib/active_admin/comments/comment.rb', line 32

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



23
24
25
26
27
28
29
30
# File 'lib/active_admin/comments/comment.rb', line 23

def self.resource_id_cast(record)
  # Postgres adapters won't compare strings to numbers (issue 34)
  if resource_id_type == :string
    record.id.to_s
  else
    record.id
  end
end

.resource_id_typeObject



38
39
40
# File 'lib/active_admin/comments/comment.rb', line 38

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

.resource_type(record) ⇒ Object



19
20
21
# File 'lib/active_admin/comments/comment.rb', line 19

def self.resource_type(record)
  record.class.base_class.name.to_s
end

.table_nameObject



42
43
44
# File 'lib/active_admin/comments/comment.rb', line 42

def self.table_name
  @table_name ||= ActiveRecord::Migrator.proper_table_name("active_admin_comments")
end