10

I have created a custom page with ActiveAdmin as follows:

ActiveAdmin.register_page "message_list" do

  controller do
    def index
      @collection = client().account.messages.list.sort_by{ |message| Date.rfc2822(message.date_sent) }.reverse
      render :layout => 'active_admin'
    end
  end
end

I have created an index.html.erb file with a table that I want to display on this page. This however is not optimal. How do I use the active admin standard table layout that also comes with pagination and display it with my table info? I know that ActiveAdmin PageDSL Class does not include #index and therefore I can't simply do:

  index do
    selectable_column
    id_column
    column :to
    column :from
    default_actions
  end

In addition to achieving the ActiveAdmin table layout on a custom page, how do I change the Title of the page itself? As of now it is called "Index".

2 Answers 2

13

An easier method would be to define an ActiveAdmin resource for your message class, Message, and limit the actions to only allow :index.

ActiveAdmin.register Message do
  actions :index

  index do
    selectable_column
    id_column
    column :to
    column :from
    default_actions
  end

  controller do
    def scoped_collection
      super.where(account_id: account.id).order(:date_sent)

      # Or provide a custom collection similar to the current implementation:
      # client().account.messages.list.sort_by{ |message| Date.rfc2822(message.date_sent) }.reverse
    end

  end
end

It is also possible to rename the resource if necessary by providing an :as option to the #register method:

ActiveAdmin.register Message, as: "Account Message" do
  # ...
end
Sign up to request clarification or add additional context in comments.

3 Comments

Super.!! Thanks CMaresh., This is what I was searching for. Great job.. How did you come to know this..?
Actually, I was thinking to hide the unnecessary rows by using jquery if i dont get solution in active admin. But, you saved me. Thanks :) :)
The usage is mentioned in the ActiveAdmin docs: Customizing resource retrieval
8

While the accepted answer works well if you can use an ActiveAdmin resource instead of a custom page, it is possible to get an index-style table on a custom page via Arbre:

<%=
  Arbre::Context.new({}, self) do
    table_for(client().account.messages, sortable: true, class: 'index_table') do
      column :id
      column :created_at
    end
  end
%>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.