I was running through tutorials for Elixir + Phoenix, and got to the part where forms start showing validation failures. Specifically this code, from Pragmatic Programmers’ “Programming Phoenix” book:
<%= form_for @changeset, user_path(@conn, :create), fn f -> %>
<%= if f.errors != [] do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below:</p>
<ul>
<%= for {attr, message} <- f.errors do %>
<li><%= humanize(attr) %> <%= message %></li>
<% end %>
</ul>
</div>
<!-- snip -->
<% end %>
I got this error: no function clause matching in Phoenix.HTML.Safe.Tuple.to_iodata/1
Couldn’t find a bloody solution anywhere. Took a long time to find IO.inspect
. The message
thing turned out to be a tuple that looked made for sprintf
- something like {"name can't be longer than %{count}", count: 1}
, so I spent forever trying to figure out if Elixir has sprintf
, looked like there might be something in :io.format()
, then I had to learn about Erlang bindings, but that wasn’t…
Ended up on #elixir-lang IRC channel, and the author of the book (Chris Mccord) pointed me to the Ecto “error helpers” in this upgrade guide. It’s a breaking change in Phoenix 1.1 + Ecto 2.0. The book is (and I imagine many tutorials are) for Phoenix 1.0.x , and I had installed the latest at 1.1.0 .
Major thanks to Chris - I have literally never had a question actually get answered on IRC. It was a last-resort measure, and it really says something about the Elixir community that someone helped me figure this out.