对灵丹妙药和凤凰城来说很新鲜。尽我所能。
defmodule Countdown.Posts.Post do use Ecto.Schema import Ecto.Changeset schema "posts" do field :description, :string field :image, Countdown.PostUploader.Type field :shot, :naive_datetime field :title, :string timestamps() end @doc false def changeset(post, attrs) do post |> cast(attrs, [:title, :shot, :description, :image]) |> cast_attachments(params, [:image]) |> validate_required([:title, :shot, :description, :image]) end end
错误:
文件lib/倒计时/posts/post.ex == * (CompileError) lib/倒计时/posts/post.ex:19:未定义函数cast_ == /3 (stdlib) lists.erl:1338::lists.foreach/2 (stdlib) erl_eval.erl:677::erl_val.do_apply/6 (elixir) lib/核/并行_==.fn:198:匿名fn/4
发布于 2018-08-05 09:05:00
据我所知,您正在使用埃多上传图像。
然后,您可能希望use Arc.Ecto.Schema包含cast_attachments宏:
defmodule Countdown.Posts.Post do
use Ecto.Schema
use Arc.Ecto.Schema
import Ecto.Changeset
schema "posts" do
field :description, :string
field :image, Countdown.PostUploader.Type
field :shot, :naive_datetime
field :title, :string
timestamps()
end
@doc false
def changeset(post, attrs) do
post
|> cast(attrs, [:title, :shot, :description, :image])
|> cast_attachments(params, [:image])
|> validate_required([:title, :shot, :description, :image])
end
endhttps://stackoverflow.com/questions/51692849
复制相似问题