defimpl Phoenix.Param to override to_param causes (FunctionClauseError) no function clause matching in Phoenix.Param.Rumbl.Video.to_param/1
Asked Answered
G

0

6

while trying to follow the examples in Programming Phoenix (book) release P1.0,
everything is working fine until Page 167 when instructed to add the lines:

defimpl Phoenix.Param, for: Rumbl.Video do
  def to_param(%{slug: slug, id: id}) do
    "#{id}-#{slug}"
  end
end

to: rumbl/web/models/video.ex

Before I add the lines, the tests pass (as expected):
https://travis-ci.org/dwyl/learn-phoenix-framework/builds/207894163#L384 tests-pass

But once the defimpl is added the tests fail:
https://travis-ci.org/dwyl/learn-phoenix-framework/builds/207901757#L349

tests-fail

The error message for two of the failing tests is:

** (FunctionClauseError) no function clause matching in Phoenix.Param.Rumbl.Video.to_param/1

Stack trace: https://travis-ci.org/dwyl/learn-phoenix-framework/builds/207901757#L349 image

Code Snapshot when these 5 lines were added: https://github.com/dwyl/learn-phoenix-framework/pull/42/commits/db72acbe83b184cd6ce3fe342ee51c3e39eb5de8

Any help with understanding this would be much appreciated!

Note: I've tried googling (for a while) ...
I've read through dozens of similar-looking questions on SO & https://elixirforum.com ...
but none were helpful. it appears I'm the only one seeing this error!
Posting a StackOverflow question is my "last resort" before giving up programming! :-(
help me obi-wan

On the "Programming Phoenix" book's errata page: https://pragprog.com/titles/phoenix/errata there is another person reporting an issue with the same code but their error is different ...

errata-not-the-same

Gulf answered 5/3, 2017 at 13:59 Comment(3)
It looks like your Video model doesn't have a slug field: github.com/dwyl/learn-phoenix-framework/blob/…. Does it work if you replace slug with url everywhere in the defimpl?Milla
adding field :slug, :string to the web/models/video.ex got me down to 1 failing test: travis-ci.org/dwyl/learn-phoenix-framework/builds/… thanks @Dogbert! :-)Gulf
Fixed: github.com/dwyl/learn-phoenix-framework/pull/42/commits/… travis-ci.org/dwyl/learn-phoenix-framework/builds/… thanks for your help @MillaGulf

© 2022 - 2024 — McMap. All rights reserved.