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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With