elixir - 渲染功能在视图中无法正常工作
问题描述
这是我的控制器代码:
def index(conn, _params) do
customers = Repo.all(Customer)
render conn, "index.json", customers: customers
end
这是客户视图中的代码
def render("index.json", %{customers: customers}) do
%{
data: render_many(customers, CustomerAdminView, "customer.json"),
}
end
def render("customer.json", %{customer: customer}) do
%{
id: customer.id,
user: customer.user,
billing_contact: customer.billing_contact
}
end
这将引发内部服务器错误。在凤凰视图文档中,我的代码与他们提供的示例相同。如果我将index.json
代码更改为此,它会起作用:
def render("index.json", %{customers: customers} = assigns) do
%{
data: render_many(customers, CustomerAdminView,
"customer.json", assigns),
}
end
为什么它适用于 render/4 而不是 render/3?
解决方案
推荐阅读
- python - 生成向量的幂并以简洁的方式将其放入 numpy 的矩阵中
- android - compileLintOptionsJavaWithJavac 失败,找不到符号
- python-xarray - 在时间维度中子集 xarray 数据集或数据数组
- cpanel - 设置 addondomain 获取“此网站不再存在或从未存在过。”
- asp.net-core - 如何在 .net Core 2.1 RazorPages 中创建确认消息?
- css - Bootstrap 4 图像叠加问题
- google-apps-script - 在 Google 表格中为具有仅查看权限的用户创建弹出消息
- python - Python连接两列但保持固定长度
- python - Python - 插入 ms 访问表
- jquery - Boostrap Datepicker 不显示/