0
我想根据以下指南https://elixircasts.io/seo-friendly-urls-with-phoenix在我的应用中实现友好网址。
正在从文章标题ok了DB产生的废料,但我不能得到这个职位,显示由塞查找何时收到以下错误:Phoenix中的友好网址1.3未定义错误
function Driverless.Articles.get_by!/2 is undefined or private
post_controller.ex
...
def show(conn, %{"id" => id}) do
post = Articles.get_by!(Post, slug: id)
render(conn, "show.html", post: post)
end
...
post.ex
...
def changeset(%Post{} = post, attrs) do
attrs = Map.merge(attrs, slug_map(attrs))
post
|> cast(attrs, [:title, :snippet, :body, :slug])
|> validate_required([:title, :snippet, :body])
end
defp slug_map(%{"title" => title}) do
slug = String.downcase(title) |> String.replace(" ", "-")
%{"slug" => slug}
end
defp slug_map(_attrs) do
%{}
end
...
我敢肯定,在某个地方有一个小错误,但只是不能发现它。
您的意思是做'Repo.get_by!'? – Dogbert
试过:'函数Repo.get_by!/ 2未定义(模块回复不可用)'。 v1.3从脚手架生成'Articles.get_by!'。 –
啊,我最近还没有使用过Phoenix 1.3,自从RC0以来,他们一直在动。 'Driverless.Articles'中有'get_by!/ 2'功能吗? – Dogbert