凤凰未定义函数转换错误

时间:2018-04-21 16:40:25

标签: terminal phoenix

我正在使用Programmming Phoneix书,我收到错误

rumbl master % → iex -S mix
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] 
[async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Compiling 9 files (.ex)

== Compilation error in file web/models/user.ex ==
** (CompileError) web/models/user.ex:6: undefined function cast/4
(stdlib) lists.erl:1338: :lists.foreach/2
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in 
Kernel.ParallelCompiler.spawn_workers/6
rumbl master % →

这是它正在讨论的user.ex文件

defmodule Rumbl.User do
  defstruct [:id, :name, :username, :password]

  def changeset(model, params \\ :empty) do
    model
    |> cast(params, ~w(name username), [])
    |> validate_length(:username, min: 1, max: 20)
  end
end

1 个答案:

答案 0 :(得分:0)

import Ecto.Changeset模块中的

Rumbl.Usercast/4Ecto.Changeset模块

中的函数
defmodule Rumbl.User do
   #import here
   import Ecto.Changeset
   defstruct [:id, :name, :username, :password]

   def changeset(model, params \\ :empty) do
     model
     |> cast(params, ~w(name username), [])
     |> validate_length(:username, min: 1, max: 20)
   end
end