问题描述
我是Phoenix和Elixir的新手,但我努力学习。这可能是一个愚蠢的简单问题,但我不知道如何在该书的索引/显示页面上显示该书作者的全名。
这是我在清单/book.ex中的查询
def get_author_full_name(author) do
from b in "books",join: a in "authors",on: b.author_id == a.id,where: a.id == ^author,select: %{id: a.id,name: concat(a.first_name,' ',a.last_name)}
end
defmodule CustomsqlFunctions do
defmacro concat(left,mid,right) do
quote do
fragment("concat(?,?,?)",unquote(left),unquote(mid),unquote(right))
end
end
end
在inventory.ex中
def display_author_full_name do
Author
|> Author.get_author_full_name()
|> Repo.all()
end
在book_controller.ex
plug :load_author_full_name when action in [:index,:show]
defp load_author_full_name(conn,_) do
assign(conn,:books,Bookstore.Inventory.display_author_full_name ())
end
我正在按照《编程Phoenix 1.4》一书中的说明显示类别的下拉列表,并做了一些小的更改以适合我的情况。有人可以指导我如何显示书作者的全名吗?我不知道我是否编写了与案例代码匹配的代码以及在视图和索引/显示页面中放入什么内容。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)