Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir Phoenix 1.3中的友好URL未定义错误_Elixir_Phoenix Framework_Friendly Url - Fatal编程技术网

Elixir Phoenix 1.3中的友好URL未定义错误

Elixir Phoenix 1.3中的友好URL未定义错误,elixir,phoenix-framework,friendly-url,Elixir,Phoenix Framework,Friendly Url,我正试图根据以下指南在我的应用程序中实现友好的URL。 正在db中根据帖子标题ok创建slug,但我无法在slug查找时显示帖子,并出现以下错误: function Driverless.Articles.get_by/2是未定义的或私有的 post_controller.ex ... def show(conn, %{"id" => id}) do post = Articles.get_by!(Post, slug: id) render(conn, "show.h

我正试图根据以下指南在我的应用程序中实现友好的URL。
正在db中根据帖子标题ok创建slug,但我无法在slug查找时显示帖子,并出现以下错误:

function Driverless.Articles.get_by/2是未定义的或私有的

post_controller.ex

...
  def show(conn, %{"id" => id}) do
    post = Articles.get_by!(Post, slug: id)
    render(conn, "show.html", post: post)
  end
...
...
  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
...
post.ex

...
  def show(conn, %{"id" => id}) do
    post = Articles.get_by!(Post, slug: id)
    render(conn, "show.html", post: post)
  end
...
...
  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
...
我肯定某个地方有个小错误,但就是看不出来

刚刚解决了这个问题:

与Elixir casts中的原始示例不同,我们将post控制器保持原样:

  def show(conn, %{"id" => id}) do
    post = Articles.get_post!(id)
    render(conn, "show.html", post: post)
  end
我刚刚更改为:

articles.ex

...
  def show(conn, %{"id" => id}) do
    post = Articles.get_by!(Post, slug: id)
    render(conn, "show.html", post: post)
  end
...
...
  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
...
发件人:

刚刚解决了这个问题:

与Elixir casts中的原始示例不同,我们将post控制器保持原样:

  def show(conn, %{"id" => id}) do
    post = Articles.get_post!(id)
    render(conn, "show.html", post: post)
  end
我刚刚更改为:

articles.ex

...
  def show(conn, %{"id" => id}) do
    post = Articles.get_by!(Post, slug: id)
    render(conn, "show.html", post: post)
  end
...
...
  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_?尝试了:
函数Repo.get\u by/2未定义(模块回购不可用)
。v1.3生成
文章。获取来自脚手架。啊,我最近没有使用Phoenix 1.3,他们从RC0开始一直在移动东西。是否有
通行证/2
无人驾驶.Articles中的功能
?控制台生成:
无人驾驶.Articles.get_by/2[Post,[slug:[3”]
No,仍然收到错误。您的意思是执行
Repo.get\u by?尝试了:
函数Repo.get\u by/2未定义(模块回购不可用)
。v1.3生成
文章。获取来自脚手架。啊,我最近没有使用Phoenix 1.3,他们从RC0开始一直在移动东西。是否有
通行证/2
无人驾驶.Articles中的功能
?控制台生成:
无人驾驶.Articles.get_by/2[Post,[slug:[3”]
否,仍然会收到错误。