开发者

Compilation error in file and undefined function

开发者 https://www.devze.com 2022-12-07 19:22 出处:网络
I\'m compiling the phoenix application and I run into error on one of my module. def toggle_complete(conn, %{"id" => id} = _params, _current_user, _claims) do

I'm compiling the phoenix application and I run into error on one of my module.

def toggle_complete(conn, %{"id" => id} = _params, _current_user, _claims) do
    with %Payout{} <- payout = Repo.get(Payout, id),
         {_count, nil} <- Payouts.toggle_prize_claims(payout),
         {:ok, payout} <- Payouts.toggle_complete(payout) do
      conn |> render("payout_simple.json", payout: payout)
    else
      nil -> {:error, :payout_not_found}
      error -> error
    end
end

Following is the error

== Compilation error in file lib/pxf/web/controllers/mart/payout_controller.ex ==
** (CompileError) lib/pxf/web/controller开发者_运维问答s/mart/payout_controller.ex:145: undefined function payout/0 (expected Pxf.Web.Mart.PayoutController to define such a function or for it to be imported, but none are available)

I'm not sure why it is showing undefined function. Am I doing something wrong for the pattern matching here?


You should assign payout in your scope.

- with %Payout{} <- payout = Repo.get(Payout, id)
+ with %Payout{} = payout <- Repo.get(Payout, id)

with/1 declares its own scope and applies a hygiene to RHOs of <-. That means the assignment in the RHO got simply discarded.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号