2016-10-07 7 views
0

私は小さなアプリケーションをPhoenixに書き込もうとしています。私は例で認証しましたhttp://meatherly.github.io/2015/05/11/phoenixauthentication/phoenix authenticate current_user

私はすべてが分かったと思いますが、私はcurrent_userのデータを扱う方法を理解できません。 私はコントローラに書く場合:

user = conn.assigns.current_user 
IO.inspect user 

私が手:

{:ok, 
%Myfiles.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, 
    encrypted_password: "$2b$12$KLDREZ08084BhHXrJR8EAuQinHn.X2X9OlfylelYiK5KSinlxfTii", 
    id: 1, inserted_at: #Ecto.DateTime<2016-10-07 21:28:51>, password: "123456", 
    password_confirmation: "123456", 
    updated_at: #Ecto.DateTime<2016-10-07 21:28:51>, username: "test"}} 

このマップではないでしょうか?ここから抜け出す方法は?あなたのcurrent_user

答えて

0

:okを含むタプルとuser struct.YouはこのようにIDを取得することができます:

{:ok, user} = conn.assigns.current_user 
IO.inspect user.id 

あなたは、構造体の詳細を読むことができhere