Custom ActiveAdmin page with index table

I 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 created an index.html.erb file with the table that I want to display on this page. This, however, is not optimal. How to use the standard table of active administrator tables, which also comes with pagination and display it with my table information? I know that the ActiveAdmin PageDSL class does not contain #index and therefore I cannot just do:

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

In addition to reaching the layout of the ActiveAdmin table on the user page, how do I change the name of the page itself? At the moment it is called "Index".

+4
source share
2

ActiveAdmin , Message :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

, , :as #register:

ActiveAdmin.register Message, as: "Account Message" do
  # ...
end
+8

, ActiveAdmin , Arbre:

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

Source: https://habr.com/ru/post/1541201/


All Articles