Phoenix CRUD generates files in a wrong directory

Lorenzo Sinisi bio photo By Lorenzo Sinisi Comment

I have started creating a Phoenix (v1.0.3) web application using Elixir (v.1.5.1), following this tutorial about building a Strawpoll clone in Elixir

I decided to document my progress and write down how does it feel to move from Rails to Phoenix building a rather simple app.

The first thing you want to do is creating a scaffold for our first model and controller. To generate a model and corresponding view, templates and controller we simply invoke mix phx.gen.html task.

The problem is that the Phoenix app lives in a subdirectory called my_app_web AND in the web folder. This is quite confusing and I did not reseach if it is a bug or intended behaviour. I guess I will find out later on or leave a comment if you know why this is the case.

If following the tutorial, I run:

mix phx.gen.html Poll polls title:string closed:boolean

This task will generate a bunch of file into the /web directory. While I need them into lib/MYAPP_web directory.

To tell Phoenix where to generate these files we have to mention this to Phoenix itself prefixing “Web “ to the name of the model we want to create.

mix phx.gen.html Web Poll polls title:string closed:boolean


If I am building a web app I don’t get why should I specify where to generate my files or why is this prefix not made mandatory. Running mix phx.gen.html Poll polls title:string closed:boolean generates all the files BUT in a wrong directory and it doesn’t give me any warning about that.

If there is an option or a flag that changes the behaviour of a command in such a way, I want either a warning or better to fail generating the files with a clear error message. I have opened an (issue on Github)[] about this problem because the documentation says that it (should default in the lib folder)[]

comments powered by Disqus