Sha256: 976530847c2a38737acd27366d56e77b625489471b42ac1b31caa54f8a587bd3

Contents?: true

Size: 940 Bytes

Versions: 12

Compression:

Stored size: 940 Bytes

Contents

module ActiveAdmin
  class Comment < ActiveRecord::Base

    self.table_name = "#{table_name_prefix}active_admin_comments#{table_name_suffix}"

    belongs_to :resource, polymorphic: true
    belongs_to :author,   polymorphic: true

    validates_presence_of :body, :namespace, :resource

    before_create :set_resource_type

    # @return [String] The name of the record to use for the polymorphic relationship
    def self.resource_type(resource)
      ResourceController::Decorators.undecorate(resource).class.base_class.name.to_s
    end

    def self.find_for_resource_in_namespace(resource, namespace)
      where(
        resource_type: resource_type(resource),
        resource_id:   resource,
        namespace:     namespace.to_s
      ).order(ActiveAdmin.application.namespaces[namespace.to_sym].comments_order)
    end

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

  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/orm/active_record/comments/comment.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/orm/active_record/comments/comment.rb
activeadmin-1.3.1 lib/active_admin/orm/active_record/comments/comment.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/orm/active_record/comments/comment.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/orm/active_record/comments/comment.rb
activeadmin-1.3.0 lib/active_admin/orm/active_record/comments/comment.rb
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/orm/active_record/comments/comment.rb
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/orm/active_record/comments/comment.rb
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/orm/active_record/comments/comment.rb
activeadmin-1.2.1 lib/active_admin/orm/active_record/comments/comment.rb
activeadmin-1.2.0 lib/active_admin/orm/active_record/comments/comment.rb
activeadmin-1.1.0 lib/active_admin/orm/active_record/comments/comment.rb