Adding Ecto model in Phoenix throws path/3 undefined

Recently, Phoenix added generators to the set of tools and they are quite good. You can generate your models with CRUD actions and HTML views with a single command.

mix phoenix.gen.html Storage storages name:string key:string

But you might run into the following error.

== Compilation error on file web/views/storage_view.ex ==
** (CompileError) web/templates/storage/edit.html.eex:4: function storage_path/3 undefined
    (stdlib) lists.erl:1336: :lists.foreach/2
    (stdlib) erl_eval.erl:657: :erl_eval.do_apply/6

Don’t panic and make sure that you add resource to your router.ex file.

resources "/storages", StorageController

Exactly as the generator output is telling you to do, if you missed it as I did for the first time.


Would you like to get the most interesting content about programming every Monday?
Sign up to Programming Digest and stay up to date!