Phoenix的自定义路线问题

时间:2017-11-09 02:27:41

标签: routes elixir phoenix-framework

这是我的路线

scope "/api/v1", Web do
    pipe_through :api

    resources "/assets", AssetController do
      get "/descendants", AssetController, :descendants, as: :descendants
    end  
end

当我这样做时:

iex(1)> import Web.Router.Helpers
Web.Router.Helpers
iex(2)> alias Web.Endpoint
Web.Endpoint
iex(3)> asset_path(Endpoint, :index)
"/api/v1/assets"
iex(4)> asset_descendants_path(Endpoint, :descendants)
** (CompileError) iex:4: undefined function asset_descendants_path/2

asset_descendants_path(Endpoint, :descendants)

出错

以下是> mix routes

asset_descendants_path  GET     /api/v1/assets/:asset_id/descendants  Web.AssetController :descendants

1 个答案:

答案 0 :(得分:3)

您似乎错过了asset_id。你需要传递它。