我有这个路由用通配符路由资源
scope "/api", MosaicApi do
pipe_through :api
# resources "/cards", CardController, except: [:new, :edit]
resources "/estimates/:product", EstimateController, except: [:new, :edit]
起初我用生成的CardController和事情的来龙去脉(至少POST /创建所做的那样),但现在我想概括为卡是一种产品类型我还有其他各种需要展示完全相同的CRUD操作的产品。所以我想变身卡*至*估计
在EstimateController我现在对这个产品
defmodule Api.CardController do
use Api.Web, :controller
alias Api.Card
def create(conn, %{"product" => product}) do
conn
|> render("result.json", product: product)
end
...
我想要做的是模式匹配带入范围相关的结构(卡.. ),但我卡住了如上的代码产生这个错误
未定义功能Api.EstimateController.init/1(模块Api.EstimateController不可用) Api.EstimateController.init(:创建)
我很困惑,init
不http://www.phoenixframework.org/docs/controllers在所有
其他迹象表明,事情多好
mix phoenix.routes
page_path GET / Api.PageController :index
estimate_path GET /api/estimates/:product Api.EstimateController :index
estimate_path GET /api/estimates/:product/:id Api.EstimateController :show
estimate_path POST /api/estimates/:product Api.EstimateController :create
没有,我有 - 看到更新的问题 –
但是现在我知道我忘了更改模块的名称 - igore我quesiton –