elixir - Phoenix Schema 在表单选择中分配了 throw Phoenix.HTML.Safe not implemented 错误
问题描述
我收到以下错误:
protocol Phoenix.HTML.Safe not implemented for {"Bad Product, LLC"}
从以下代码:
审查控制器
def new(conn, _params) do # creating a review, the Company is a schema association
changeset = Accounts.change_review(%Review{})
companies = Repo.all from c in Company, select: {c.name}
render(conn, "new.html", changeset: changeset, companies: companies)
end
模板:
<%= select f, :company_id, @companies %>
通过对 SO 的研究,我尝试添加inspect
:
<%= select f, :company_id, inspect @companies %>
但这会引发以下错误:
protocol Enumerable not implemented for "[{\"Bad Product, LLC\"}]"
看起来它正试图按预期逃避它,所以我重构了控制器以枚举公司:
render(conn, "new.html", changeset: changeset, companies: Accounts.list_companies() |> Enum.map(&{&1.name}))
但它仍然会引发Enumerable not implemented
错误。
谢谢!
解决方案
公司 = Repo.all from c in Company,选择:{c.name}
在这里您只选择名称
而您正在尝试访问 company_id
尝试
公司 = Repo.all(公司)
推荐阅读
- python-3.x - python格式化问题解析子元素
- java - 从 SpringBoot 获取 protobuf 消息对象列表
- sql-server - Visual Studio 数据库项目参考
- java - com.googlecode.objectify.LoadException:时间戳超出范围错误
- azure - SignalR - 验证用户
- oauth-2.0 - Swagger:授权令牌未传递到请求标头中
- python - 如何从python中的整数生成列表?
- ruby-on-rails - 在 Rails 中寻找一个 gem,它维护特定模型的数据中所做的每个更改的版本
- css - Break-inside 不适用于材质 ui
- javascript - 如何忽略标准中的 eslint 规则