RailsAdmin设置默认集合操作

时间:2014-08-07 08:55:05

标签: ruby-on-rails rails-admin

我已经实现了一个新的集合操作,并在rails admin初始化程序中声明了它:

config.actions do
  # root actions
  dashboard                 
  # collection actions
  scope_filter  #my custom action
  index                         
  new
  show
  edit
  delete
end

导航到模型时,默认操作始终为index,是否可以覆盖此操作并将scope_filter操作设置为默认操作?

(rails_admin 0.6.2 with Rails 4.1)

[edit]在评论中提到这里是scope_filter插件的摘录:

require 'rails_admin/config/actions/base'

module RailsAdminScopeFilter
  class RailsAdmin::Config::Model
    register_instance_option :scope_filter do
      nil
    end
  end

  class ScopeFilter < RailsAdmin::Config::Actions::Base
    RailsAdmin::Config::Actions.register(self)

    register_instance_option :collection do
      true
    end

    register_instance_option :http_methods do
      [:get, :post]
    end

    register_instance_option :visible? do
      current_model = ::RailsAdmin::Config.model(bindings[:abstract_model])
      authorized? && current_model.scope_filter
    end

    register_instance_option :controller do
      proc do
        if request.get?
          # GET, displaying data
          # Blablah
        else
          # POST, means that we want reorder stuff baby!
          # dosomethin else
        end
      end
    end
  end
end

1 个答案:

答案 0 :(得分:0)

我认为最简单的方法是在索引操作中添加重定向。

def Index
  redirect_to action: 'scope_filter'
end