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

我想在页面的成员操作之一中使用自定义控制器操作。我收到未定义的方法错误。
    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:职位不是模特。只是一页。

yichaohao 回答:活动管理员-在“收集”操作中使用控制器方法

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

在帮助程序文件中添加方法,然后尝试从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
本文链接:https://www.f2er.com/3139055.html

大家都在问