相关疑难解决方法(0)

POST时的Phoenix.ActionClauseError,没有匹配的动作子句来处理请求

每当我发布到/ api/subastas时,我都会收到此错误

Phoenix.ActionClauseError at POST /api/subastas/ bad request to IascSubastas.SubastaController.create, no matching action clause to process request
Run Code Online (Sandbox Code Playgroud)

如果我运行mix phoenix.routes,我看到:create正确路由到POST/api/subastas

这是router.ex

defmodule IascSubastas.Router do
  use IascSubastas.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", IascSubastas do
    pipe_through :browser # Use the default browser stack

    get "/", PageController, :index
  end

  # Other scopes may use custom stacks.
  scope "/api", IascSubastas do
    pipe_through :api

    resources "/subastas", …
Run Code Online (Sandbox Code Playgroud)

rest controller elixir

1
推荐指数
1
解决办法
3652
查看次数

POST时的Phoenix.ActionClauseError,对Myapp.StatisticsController.calculate的错误请求

我有一个Statistics控制器,它获取date_fromdate_to计算之间进行收入的订单数量和金额date_fromdate_to.

def calculate(conn,  %{"statistics" => %{"date_from" => date_from, "date_to" => date_to}}) do

revenue = Repo.one(from p in Order, where: p.created_date >= ^date_from and p.created_date <= ^date_to, select: sum(p.paied))
order = Repo.one(from p in Order, where: p.created_date >= ^date_from and p.created_date <= ^date_to, select: count(p.id))

conn
|> put_resp_content_type("application/json")
|> render("statistics.json", order: order, revenue: revenue)

end
Run Code Online (Sandbox Code Playgroud)

以下是statistics.view和router,它会导致错误.

  def render("statistics.json", %{order: order, revenue: revenue}) do

%{
  order: order

}

%{
  revenue: revenue
} …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework

1
推荐指数
1
解决办法
784
查看次数

标签 统计

elixir ×2

controller ×1

phoenix-framework ×1

rest ×1