Using the Phoenix Framework, I want to implement a nested form such as fields_for RoR. Today I tried to implement it with input_for, but I got an error.
Referring to a Phoenix Framework white paper, I could find a sample with input_for. It describes only a pattern with embed_one association. And I met an error with the has_many association.
How can I implement the nested form for the has_many association correctly?
The scheme is as follows:
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
And I implemented form.html.eex as below:
<%= form_for @changeset, @action, fn f -> %> <%= inputs_for f, :emails, fn ef -> %> <% end %> <% end %>
This will result in an error. Argument Error: Unknown field: Email messages .
source share