我有一個'收音機'的模型,並在我的主頁(template/page/index.html.eex)
我正在拉最後的錄音。這可以正常工作,但我很努力讓鏈接工作到特定記錄的顯示頁面(template/radio/show.html.eex)
。不能得到菲尼克斯連接路線上班
在控制檯中我得到:
== Compilation error on file web/controllers/radio_controller.ex ==
** (CompileError) web/controllers/radio_controller.ex:31: undefined function last_radio/0
上線很多例子使用@conn:
<%= link "Show", to: radio_path(@conn, :show, radio), class: "button" %>
我一直在努力,這個轉變讓我的last_radio
查詢:
<%= link "Show", to: radio_path(@last_radio, :show, radio), class: "button" %>
但這並不奏效。
也不:
<%= link "Show", to: radio_path(@conn, :show, last_radio), class: "button" %>
radio_controller
defmodule Radios.RadioController do
use Radios.Web, :controller
alias Radios.Radio
def index(conn, _params) do
radios = Repo.all(Radio)
render conn, "index.html"
end
def show(conn, %{"id" => id}) do
radio = Repo.get!(Radio, id)
render(conn, "show.html", radio: radio)
end
page_controller
defmodule Radios.PageController do
use Radios.Web, :controller
alias Radios.Radio
def index(conn, _params) do
last_radio = Radio |> last |> Repo.one
#|> Radio.sorted
#|> Radios.Repo.one
render(conn, "index.html", last_radio: last_radio)
end
end
什麼是I D錯了嗎?
錯誤在第31行,但是,您提供的代碼顯示的行少於31行。控制器是否比這更長? –
這是的,但你的答案已經修復了。當然是 –