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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -