在liveview
,我怎样才能将用户数据传递leex
给context
?我有phx.gen.live
一个profiles
上下文,我想在每次用户创建新配置文件时将 user_id 添加到配置文件中。我将 create_profile 代码更改为:
**profiles.ex (context)**
def create_profile(attrs \\ %{}, userid) do
attrs = Map.put(attrs, "user_id", userid)
%Profile{}
|> Profile.changeset(attrs)
|> Repo.insert()
end
我正在使用pow
,所以在正常的凤凰情况下,我会这样做:
user = Pow.Plug.current_user(conn) #<-- this is conn
Profiles.create_profile(profile_params, user.id)
但在liveview
,而不是conn
,它使用socket
. 所以我不知道该怎么做。