Nihal Nizar
Nihal Nizar

Reputation: 25

Active admin - Use controller method in Collection actions

i want to use a custom controller action in one of the member actions of the page . Iam getting undefined method error .

    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 throws error .
PS: Post is not a model . Just a page .

Upvotes: 1

Views: 1956

Answers (1)

Vishnu Vijayakumar
Vishnu Vijayakumar

Reputation: 48

Add method in Helper. You can access the method from controller and all the collection actions.

Add method in helper file and try to call it from 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

Upvotes: 1

Related Questions