Alexander Popov
Alexander Popov

Reputation: 25005

How to create a custom page in ActiveAdmin gem

Ruby 2.0, Rails 4.0, PSQL 9.3

In the ActiveAdmin documentation there is the example:

ActiveAdmin.register_page "My Page" do
  content do
    para "Hello World"
  end
end

Where do I put this code? The documentation says:

In the above example, a new page will be created at /admin/my_page with the title “My Page” and the content of “Hello World”.

This implies that such a file would be created automatically somehow? Nevertheless, I created a file named import.rb under app/admin and the Import item in the menu does appear. However, I am not able to use HTML, as this file is .rb and not .erb. I suppose, in order to be able to use html, I need to create a partial and den render it within the content method. But when I look under app/views there is not admin folder (only layouts). Does this mean I need to create the folder admin under app/views? If yes, where should I put my partial - directly under app/views/admin or under a new folder app/views/admin/import?

I am sorry for the menu questions, but the documentation of ActiveAdmin is pretty modest. I would really appreciate if someone could provide a more details explanation of the steps needed for creating and adding content to a new page in ActiveAdmin.

Upvotes: 7

Views: 5750

Answers (1)

kristinalim
kristinalim

Reputation: 3459

What the documentation meant was that if you create a new custom page app/admin/my_page.rb, this page will be available in the URL /admin/my_page (if you are using the default ActiveAdmin configuration).

Regarding rendering of an ERB or HAML partials for your my_page.rb, you can do it this way:

ActiveAdmin.register_page "My Page" do
  content do
    render :partial => 'about'
  end
end

This will look under the directory app/views/admin/my_page/. If the directories do not exist, create them. Also, you can still specify other directories by referencing the full template path (e.g. shared/sections/about) like you would for a non-ActiveAdmin controller.

Upvotes: 10

Related Questions