gpt4 book ai didi

phoenix-framework - Phoenix 框架 : Is inputs_for available for the has_many associations?

转载 作者:行者123 更新时间:2023-12-01 03:39:42 24 4
gpt4 key购买 nike

使用Phoenix Framework,我想实现像RoR的fields_for这样的嵌套表单。
今天我试图用inputs_for来实现它,但我得到了错误。

引用Phoenix Framework的官方文档,我可以找到带有inputs_for的示例。它仅描述具有 embed_one 关联的示例。我遇到了 has_many 关联的错误。

如何正确实现 has_many 关联的嵌套表单?

示意图如下:

defmodule AnApp.User do
use PhoenixBlog.Web, :model

schema "users" do
field :handle, :string
field :password_digest, :string

has_many :emails
end
end

defmodule AnApp.Email do
use PhoenixBlog.Web, :model

schema "emails" do
field :address, :string
end
end

我实现了 form.html.eex 如下:
<%= form_for @changeset, @action, fn f -> %>
<%= inputs_for f, :emails, fn ef -> %>
<% end %>
<% end %>

这会导致错误 参数错误:未知字段:电子邮件 .

最佳答案

不,现在它只支持嵌入。接下来我们正在努力支持协会。新发布的Phoenix.Ecto中的错误信息也应该比较清楚。

关于phoenix-framework - Phoenix 框架 : Is inputs_for available for the has_many associations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31735128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com