Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

The parent nested resource does not handle errors #82

Open
quexpl opened this issue Dec 13, 2019 · 0 comments · May be fixed by #83
Open

The parent nested resource does not handle errors #82

quexpl opened this issue Dec 13, 2019 · 0 comments · May be fixed by #83

Comments

@quexpl
Copy link
Collaborator

quexpl commented Dec 13, 2019

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.

@quexpl quexpl linked a pull request Dec 13, 2019 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant