如何覆盖activeadmin gem中的私有方法

时间:2016-05-10 06:36:54

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

我想覆盖模块ActionItems中的私有方法 https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/resource/action_items.rb

我尝试在文件夹libs/active_admin/resource/libs/active_admin/中创建文件action_items.rb

在我的文件action_items.rb

module ActiveAdmin
  class Resource
    module ActionItems

      private
        def add_default_new_action_item
          add_action_item :new, only: :index do
            if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
              link_to I18n.t('active_admin.new_model', model: active_admin_config.resource_label), new_resource_path, target: "_parent"
            end
          end
        end

        # Adds the default Edit link on show
        def add_default_edit_action_item
          add_action_item :edit, only: :show do
            if controller.action_methods.include?('edit') && authorized?(ActiveAdmin::Auth::UPDATE, resource)
              link_to I18n.t('active_admin.edit_model', model: active_admin_config.resource_label), edit_resource_path(resource), target: "_parent"
            end
          end
        end

        # Adds the default Destroy link on show
        def add_default_show_action_item
          add_action_item :destroy, only: :show do
            if controller.action_methods.include?('destroy') && authorized?(ActiveAdmin::Auth::DESTROY, resource)
              link_to I18n.t('active_admin.delete_model', model: active_admin_config.resource_label), resource_path(resource),
                method: :delete, data: {confirm: I18n.t('active_admin.delete_confirmation')}
            end
          end
        end
    end
  end
end

但它不起作用,如何解决这个问题? (覆盖私有方法add_default_new_action_item)

0 个答案:

没有答案