Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用“从插头分配到视图”(elixir/phoenix)_Elixir_Phoenix Framework_Plug - Fatal编程技术网

使用“从插头分配到视图”(elixir/phoenix)

使用“从插头分配到视图”(elixir/phoenix),elixir,phoenix-framework,plug,Elixir,Phoenix Framework,Plug,我有我的api管道,我想在其中添加一个插件,该插件基本上在数据库中执行一些操作,并根据响应执行分配,然后在视图中使用该分配 我在将分配从插件传递到视图时遇到问题 web/router.ex pipeline :api do plug ApiV2.Plug.Authenticate, repo: Auth.Repo plug :accepts, ["json"] end defmodule ApiV2.AddressController do use ApiV2.Web, :cont

我有我的api管道,我想在其中添加一个插件,该插件基本上在数据库中执行一些操作,并根据响应执行分配,然后在视图中使用该分配

我在将分配从插件传递到视图时遇到问题

web/router.ex

pipeline :api do
  plug ApiV2.Plug.Authenticate, repo: Auth.Repo
  plug :accepts, ["json"]
end
defmodule ApiV2.AddressController do
  use ApiV2.Web, :controller

  alias ApiV2.Address

  def index(conn, params) do
    json conn, @current_user
  end
end
web/controllers/auth.ex(仅分配)

web/controllers/address\u controller.ex

pipeline :api do
  plug ApiV2.Plug.Authenticate, repo: Auth.Repo
  plug :accepts, ["json"]
end
defmodule ApiV2.AddressController do
  use ApiV2.Web, :controller

  alias ApiV2.Address

  def index(conn, params) do
    json conn, @current_user
  end
end
我已经到达了它试图返回的点:当前用户(我想),但是,由于赋值错误,它只返回

null
我错过了什么


谢谢使用
assign
设置的值可在
conn.assigns
映射中找到
@current_user
是一个模块属性,它返回
nil
,因为它未在此模块中设置

这应该起作用:

json conn, conn.assigns.current_user