vinhnglx / vinhnglx.github.io

0 stars 0 forks source link

TIL_07_Sep_2017 - Enumerable requires a map not a struct in Elixir #33

Open vinhnglx opened 7 years ago

vinhnglx commented 7 years ago
    test/controllers/quote_controller_test.exs:109
     ** (Protocol.UndefinedError) protocol Enumerable not implemented for %Sample.Quote

As this answer, the Enumerable requires a map, not a struct.

So, the code needs to change to

          quote = %{quote: Repo.preload(quote, :user)} # A Map
          render(conn, "edit.html", quote: quote, changeset: changeset)

And the view will be @quote.quote.user and @quote.quote, because the @quote is a map.

<h2>Edit Quote</h2>

<%= render "form.html", changeset: @changeset, types: @types,
                        action: user_quote_path(@conn, :update, @quote.quote.user, @quote.quote) %>

<%= link "Back", to: user_quote_path(@conn, :index, @quote.quote.user, @quote)