【发布时间】:2016-02-28 12:25:19
【问题描述】:
我正在尝试在 for-each 循环中设置用户模型的某些属性,但我不断收到以下错误
无法在匹配中调用远程函数 x.token/0 (elixir) src/elixir_fn.erl:9: 匿名 fn/3 在 :elixir_fn.translate/3 (stdlib)lists.erl:1353::lists.mapfoldl/3 (elixir) src/elixir_fn.erl:14: :elixir_fn.translate/3
方法:
Enum.each(users, fn(user) ->
user.token = Comeonin.Bcrypt.hashpwsalt(to_string(user.id))
end)
【问题讨论】:
-
你导入 Comeonin.Bcrypt 了吗?如果你这样做了,你可以在没有前缀的情况下调用 hashpwsalt,这可能会导致你出现问题。
-
@GavinBrelstaff 试过了,还是不行
-
这里 hexdocs.pm/comeonin/Comeonin.Bcrypt.html 说有一个函数 init() - 在调用 hashpwsalt 之前需要调用它吗?