活动管理员 - 在收集操作中使用控制器方法

Active admin - Use controller method in Collection actions

我想在页面的其中一个成员操作中使用自定义控制器操作。我收到未定义的方法错误。

    ActiveAdmin.register_page Post do
      controller do
        def get_last_post
        end
      end

    collection_action :get_details, method: :get do 
      data = get_last_post
    end

    end

data = get_last_post 抛出错误。
PS: Post 不是模特。只是一页。

在助手中添加方法。您可以从控制器和所有收集操作访问该方法。

在辅助文件中添加方法并尝试从 collection_action

中调用它
module PostHelper
  def get_last_post
  end
end

ActiveAdmin.register_page Post do
  collection_action :get_details, method: :get do 
    data = get_last_post
  end
end