Hey with the usual resources everything is working nicely, but i I want to add any custom named function in from the controller to use on given path it gives me this error:
protocol Enumerable not implemented for %CabifyChallenge.Web.Item{meta : ecto .Schema.Metadata<:loaded, “items”>, id: 1, inserted_at: ~N[2018-11-27 08:33:21.739806], name: “MUG”, price: 7.5, quantity: 0, updated_at: ~N[2018-11-27 08:33:21.741303]}. 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
So I am trying to add into the controller like:
def scan(conn, %{"id" => id, "item" => item_params}) do
IO.puts('hehexd')
end
and I want t use this in the router like:
put("/cart", ItemController, :scan)
resources("/", ItemController)
I would prefer to use it on the same path if possible.
and where the error is pointing to is in the html, so the error happens on the index.html and the part looks like this:
<span><%= link "Scan", to: item_path(@conn, :scan, item), class: "btn btn-primary btn-xs" %></span>
How can I fix this?
idi527
November 27, 2018, 9:12am
2
Can you post the stacktrace which leads to your error?
(Protocol.UndefinedError) protocol Enumerable not implemented for %Challenge.Web.Item{meta : ecto .Schema.Metadata<:loaded, “items”>, id: 1, inserted_at: ~N[2018-11-27 08:33:21.739806], name: “MUG”, price: 7.5, quantity: 0, updated_at: ~N[2018-11-27 08:33:21.741303]}. 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
(elixir) /home/vagrant/2018-09-24_12-39-03/scripts/elixir/deb/elixir_1.7.3-1/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) /home/vagrant/2018-09-24_12-39-03/scripts/elixir/deb/elixir_1.7.3-1/lib/elixir/lib/enum.ex:141: Enumerable.reduce/3
(elixir) lib/enum.ex:2979: Enum.reduce/3
(_challenge) lib/_challenge_web/router.ex:1: ChallengeWeb.Router.Helpers.segments/3
(_challenge) lib/_challenge_web/router.ex:1: ChallengeWeb.Router.Helpers.item_path/3
(_challenge) lib/_challenge_web/templates/item/index.html.eex:20: anonymous fn/3 in ChallengeWeb.ItemView.“index.html”/1
(elixir) lib/enum.ex:1925: Enum.“-reduce/3-lists^foldl/2-0-”/3
(_challenge) lib/_challenge_web/templates/item/index.html.eex:13: ChallengeWeb.ItemView.“index.html”/1
(_challenge) lib/_challenge_web/templates/layout/app.html.eex:21: ChallengeWeb.LayoutView.“app.html”/1
(phoenix) lib/phoenix/view.ex:332: Phoenix.View.render_to_iodata/3
(phoenix) lib/phoenix/controller.ex:740: Phoenix.Controller.do_render/4
(_challenge) lib/_challenge_web/controllers/item_controller.ex:1: ChallengeWeb.ItemController.action/2
(_challenge) lib/_challenge_web/controllers/item_controller.ex:1: ChallengeWeb.ItemController.phoenix_controller_pipeline/2
(_challenge) lib/_challenge_web/endpoint.ex:1: ChallengeWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:278: Phoenix.Router.call /1
(_challenge) lib/_challenge_web/endpoint.ex:1: ChallengeWeb.Endpoint.plug_builder_call/2
(_challenge) lib/plug/debugger.ex:122: ChallengeWeb.Endpoint.“call (overridable 3)”/2
(_challenge) lib/_challenge_web/endpoint.ex:1: ChallengeWeb.Endpoint.call/2
(plug_cowboy) lib/plug/cowboy/handler.ex:18: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) /home/holo/Projects/_challenge/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
and it only gives this error if I try to add the :scan to the button
Should the item you pass to the helper end up as "id"
or "item"
?
ok so in the scan i only need the id, my bad there, but still the same issue, and in the html, i am following the pattern:
<span><%= link "Scan", to: item_path(@conn, :scan, item), class: "btn btn-primary btn-xs" %></span>
<span><%= link "Show", to: item_path(@conn, :show, item), class: "btn btn-default btn-xs" %></span>
<span><%= link "Edit", to: item_path(@conn, :edit, item), class: "btn btn-default btn-xs" %></span>
put "/cart/:id", ItemController , :scan
1 Like
ok the error is gone with that but says no route found, and if i remove the cart part from that and just leave
put "/:id", ItemController , :scan
then it just show the :show helper? is it what it is called?
so it doesnt hit the :scan, even before the log didnt happen
It’s a put route. Your link in the HTML is sending a GET request.
1 Like
yes, if i change it to get it is there