これは、from要素からカスタム日付を作成しています。私は人の誕生日と月を収集するフォームを持っています(私は年に興味がありません)。私は私のモデルでは複数のフォーム要素から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
現在、私が取得するので、私はこの記事を約あるday_and_month_of_birth
要素のためのフォームのエントリを作成するには、以下を使用しますエラーunrecognized date %{"day" => "1", "month" => "1"}
。
registration
スキーマには、day
フィールドとmonth
フィールドがないためだと思います。私の質問は次のとおりです
私は生年に興味がないので、Ecto.Dateはまだday_and_month_of_birth
フィールドに使用するのに適したタイプですか?
第2に、どうすればエラーを解決できますか?