ja_resource v0.3.1 JaResource.Attributes behaviour
Provides the permitted_attributes/3
callback used for filtering attributes.
This behaviour is used by the following JaResource actions:
- JaResource.Delete
- JaResource.Create
Summary
Callbacks
Used to determine which attributes are permitted during create and update
Callbacks
Specs
permitted_attributes(Plug.Conn.t, JaResource.attributes, :update | :create) :: JaResource.attributes
Used to determine which attributes are permitted during create and update.
The attributes map (the second argument) is a “flattened” version including
the values at data/attributes
, data/type
and any relationship values in
data/relationships/[name]/data/id
as name_id
.
The third argument is the atom of the action being called.
Example:
defmodule MyApp.V1.PostController do
use MyApp.Web, :controller
use JaResource
def permitted_attributes(conn, attrs, :create) do
attrs
|> Map.take(~w(title body type category_id))
|> Map.merge("author_id", conn.assigns[:current_user])
end
def permitted_attributes(_conn, attrs, :update) do
Map.take(attrs, ~w(title body type category_id))
end
end