Create a dashboard page¶
An Easy page is a dashboard whose layout and modules users can edit. A dashboard consists of an EasyPage record, a controller registered with EasyExtensions::EasyPageHandler, routes and two views.
Paths on this page are relative to your plugin directory, for example plugins/easyproject/easy_plugins/modification_acme/.
Data migration¶
Create the EasyPage record in a data migration (db/data/). Its available zones are created for you from the layout.
| db/data/20260101120000_create_my_dashboard.rb | |
|---|---|
Available layouts are two_column_header_three_rows_right_sidebar, two_column_header_first_wider and two_column_header_and_footer (EasyPage::PAGE_LAYOUTS).
Controller¶
Register the page in a controller. The handler defines the show and edit actions and the page authorisation.
| app/controllers/my_dashboard_controller.rb | |
|---|---|
Arguments:
page_name: thepage_nameof theEasyPagerecord. The record must exist in the database.path: aprocreturning the path of the dashboard.show_action: the action that displays the dashboard.edit_action: the action where users add and arrange modules.
Optional page_context and entity arguments are described in EasyExtensions::EasyPageHandler.generate_module.
Routes¶
| config/routes.rb | |
|---|---|
Views¶
Create app/views/my_dashboard/index.html.erb and app/views/my_dashboard/layout.html.erb. render_aria_headings is required; the button opens the layout editor for users who can edit the page:
<%= render_aria_headings %>
<%= render_easy_page_bottom_buttons(layout_my_dashboard_index_path(t: params[:t])) if @page_editable %>
Tests¶
Test the routes with a request spec in test/spec/requests/my_dashboard_controller_spec.rb: