elixir - Where to put helper module on Phoenix Framework -
i want add helper module request using
http://hexdocs.pm/httpoison/httpoison.base.html
but when put defmodule
in
/lib/shopper/callapi.ex
and use
in
/web.ex
def controller quote use phoenix.controller alias shopper.repo import ecto.model import ecto.query, only: [from: 1, from: 2] import shopper.router.helpers use shopper.callapi end
end
the compiler failed
== compilation error on file web/controllers/page_controller.ex == ** (undefinedfunctionerror) undefined function: shopper.callapi.__using__/1 shopper.callapi.__using__([]) web/controllers/page_controller.ex:2: (module)
so... define callapi.ex , should declare it?
when call use shopper.callapi
, __using__/1
macro called - specific meta-programming. if want use functions defined in shopper.callapi
in module use alias shopper.callapi
instead.
the differences between alias
, require
, import
documented in alias, require , import , using
documented in domain specific languages.
as aside, in elixir projects, files named in snake_case - call_api.ex
instead of callapi.ex
.
Comments
Post a Comment