这就是我特意从元素创建自定义日期。我有一张收集人的出生日期和月份的表格(我对这一年不感兴趣)。所以我用下面的,以创建day_and_month_of_birth
元素的形式进入这个职位是:从多个表单元素创建Elixir Ecto数据
<div class="form-group">
<div class="row">
<div class="col-md-5">Day/Month of Birth</div>
<%= date_select f, :day_and_month_of_birth, builder: fn b -> %>
<div class="col-md-3">
<%= b.(:day, []) %>
</div>
/
<div class="col-md-4">
<%= b.(:month, []) %>
</div>
<% end %>
<%= error_tag f, :day_and_month_of_birth %>
</div>
</div>
在我的模型,我有:
defmodule RocfDev.Registration do
use RocfDev.Web, :model
schema "registration" do
field :title, :string, virtual: true
field :firstname, :string, virtual: true
field :surname, :string, virtual: true
field :day_and_month_of_birth, Ecto.Date, virtual: true
end
def changeset(model, params \\ %{}) do
model
|> cast(params, [
:title,
:firstname,
:surname,
:day_and_month_of_birth
])
end
目前,当我张贴的形式,我得到的错误unrecognized date %{"day" => "1", "month" => "1"}
。
我想这是因为在registration
模式中没有day
和month
字段。我的问题是:
1,由于我对出生年份不感兴趣,Ecto.Date仍然是适用于day_and_month_of_birth
字段的类型吗?
2,如何解决错误?