The parent nested resource does not handle errors
quexpl opened this issue · 0 comments
quexpl commented
We have the Network
model which belongs to the Hypervisor
, and /networks
resources are nested like this:
resources "/hypervisors", HypervisorController do
resources "/networks", NetworkController, only: [:new, :create, :index]
end
According to the docs persisted
option is a bless for nested resources.
plug :load_resource,
model: Hypervisor,
id_name: "hypervisor_id",
only: [:index, :create, :new],
preload: [:hypervisor_type],
persisted: true
This is almost perfect. For :index
, :new
or :create
action the handle_not_found/2
will never call error handler. For our case it's essential to allow visit nested pages only if parent resource exists.
So now when I visit /hypervisors/999/networks
the conn.assigns[:hypervisor
will be nil
, I'd expect a 404 error.