-
Notifications
You must be signed in to change notification settings - Fork 272
How to add custom actions
David Long edited this page May 25, 2017
·
3 revisions
The following illustrates how to customize actions, bypassing the default controller action for a given resource.
- Create a new controller with the given action
- Add a route for the action
See admin_resource_controller.ex
for ExAdmin's implementation of the resource controller.
# web/controllers/model_controller.ex
defmodule MyProject.Admin.ModelController do
@resource "models"
use ExAdmin.Web, :resource_controller
def update(conn, _defn, _params) do
resource = conn.assigns.resource
changeset = apply(defn.resource_model, defn.update_changeset, [resource, params[defn.resource_name]])
# ...
end
end
# web/router.ex
scope "/admin", MyProject.Admin do
put "/models/:id", ModelController, :update
end