RAILS - ActiveAdmin禁用评论删除?

时间:2017-01-11 16:30:39

标签: ruby-on-rails ruby-on-rails-4 activerecord activeadmin

在整合ActiveAdmin面板后,我试图找到哪里可以修改任何选项以消除delete comments

的可能性

但我无法在任何地方找到这个

可以删除comments删除吗?

1 个答案:

答案 0 :(得分:1)

解决方案1 ​​

您可以按照此处所述提供自己的AuthorizationAdapter:http://activeadmin.info/docs/13-authorization-adapter.html

您的authorized?方法应为:

  def authorized?(action, subject = nil)
    !(action == ActiveAdmin::Auth::DESTROY && subject.is_a?(ActiveAdmin::Comment))
  end

解决方案2

或者您可以覆盖生成评论部分的ActiveAdmin build_comment方法。

将其放入lib/active_admin.rb

# Overriding ActiveAdmin's `build_comment` method.
# The original code is here: 
# https://github.com/activeadmin/activeadmin/blob/d01155f73a0e2cc27d712792270357e2b3759d05/lib/active_admin/orm/active_record/comments/views/active_admin_comments.rb
#
module ActiveAdmin
  module Comments
    module Views
      class Comments < ActiveAdmin::Views::Panel
        def build_comment(comment)
          div for: comment do
            div class: 'active_admin_comment_meta' do
              h4 class: 'active_admin_comment_author' do
                comment.author ? auto_link(comment.author) : I18n.t('active_admin.comments.author_missing')
              end
              span pretty_format comment.created_at
            end
            div class: 'active_admin_comment_body' do
              simple_format comment.body
            end
          end
        end
      end
    end
  end
end

第一种解决方案更好。