我有一个带有字段的Ecto模型:
field :coordinates, {:array, {:array, :float}}
现在,在show
操作中,这可以很好地呈现,例如作为字符串[[0.0, 0.1]]
。但是,当我尝试为edit
函数(作为字符串)呈现表单时,我收到以下错误:
** (ArgumentError) lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: 0.0
(phoenix_html) lib/phoenix_html/safe.ex:80: Phoenix.HTML.Safe.List.to_iodata/1
(phoenix_html) lib/phoenix_html/safe.ex:49: Phoenix.HTML.Safe.List.to_iodata/1
据我所知,这与Html.Safe
的本土冲突相冲突。虽然我不确定它为什么会在表单中发生冲突,但不会在show
视图中冲突。
表格代码:
<%= form_for @changeset, @action, fn f -> %>
<div class="form-group">
<%= label f, "coordinates (e.g: [[0.1, 0.2], [0.3, 0.4]])", class: "control-label" %>
<%= text_input f, :coordinates, class: "form-control" %>
<%= error_tag f, :coordinates %>
</div>
控制器:
def edit(conn, %{...}) do
item = Repo.get!(Item, id)
changeset = Item.changeset(block)
render(conn, "edit.html", item: item, changeset: changeset)
end