Protocol Enumerable not Implemented for struct

Trying to implement a basic email form to send an email within the app.

I’ve got a link in index.html.eex in my templates/access_key template: <span><%= link "Email", to: Routes.email_path(@conn, :new, access_key), class: "btn btn-danger btn-xs" %></span>

This should take you to the email templates using functions defined in email_controller. But when trying to render the email button in localhost:4000/access_keys I get a big error

Request: GET /access_keys/
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol Enumerable not implemented for %Blackbook.Accounts.AccessKey{__meta__: #Ecto.Schema.Metadata<:loaded, "access_keys">, access_key: "f57db6be-b9e1-4f79-896c-a29c0604190f", id: 1, inserted_at: ~N[2018-11-27 23:00:16], updated_at: ~N[2018-11-27 23:00:16], user_type: %Blackbook.Accounts.UserType{__meta__: #Ecto.Schema.Metadata<:loaded, "user_types">, actions: [], id: 1, inserted_at: ~N[2018-11-27 22:59:07], type: "Admin", updated_at: ~N[2018-11-27 22:59:07], user: #Ecto.Association.NotLoaded<association :user is not loaded>}, user_type_id: 1}. This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Postgrex.Stream, Range, Stream

I’d like to show the access_key on top of the email form for easy copy/paste (or preferably inside the subject form itself by default) so I’m trying to pass that along as well.
I’ve seen a couple issues involving this error but haven’t been able to pin down my issue exactly.

github.com/codball/blackbook is the repo, thanks in advance. :slight_smile:

:wave:

If you want to generate a link to /access_keys, can you try

<span><%= link "Email", to: Routes.email_path(@conn, :new), class: "btn btn-danger btn-xs" %></span>

?

If you want to generate a link to /access_keys/:id, can you try using a show route instead

<span><%= link "Email", to: Routes.email_path(@conn, :show, access_key), class: "btn btn-danger btn-xs" %></span>

?

2 Likes

I did not realize the controller function names were so strict or actually meant anything, looks like I’ve got some reading to do :stuck_out_tongue:

You might follow this link on REST to understand why.

Or You might use the following command to see your routes.

mix phx.routes