0

基本的にデータベースでいくつかの操作を行うプラグを追加したいAPIパイプラインがあり、応答に基づいて割り当てを行い、それをビューで使用します。

プラグからビューへの割り当ての受け渡しに問題があります。

web/router.ex

pipeline :api do
  plug ApiV2.Plug.Authenticate, repo: Auth.Repo
  plug :accepts, ["json"]
end

web/controllers/auth.ex (割り当てのみ)

defmodule ApiV2.Plug.Authenticate do
     @behaviour Plug
     import Plug.Conn
     import Phoenix.Controller

  def init(opts), do: opts

  def call(conn, _opts) do
    assign(conn, :current_user, 'user')
  end

end

web/controllers/address_controller.ex

defmodule ApiV2.AddressController do
  use ApiV2.Web, :controller

  alias ApiV2.Address

  def index(conn, params) do
    json conn, @current_user
  end
end

:current_user を返そうとするところまで来ましたが (おそらく)、割り当てが間違っているため、返されるだけです。

null

私は何が欠けていますか?

ありがとう

4

1 に答える 1