Phoenix.gen.html for production?

Hi there,

In Rails there are individual generator commands for every part of our MVC app, like rails g model, rails g controller etc. And devs tends to recommend these commands instead of full-fleged rails g scaffold command. They said, never use scaffold for “real” app.

And here, in Phoenix… There’s only one generator command for HTML based app, which is phoenix.gen.html. Correct me if I’m wrong, but I didn’t see any other individual generator for this purpose.

So, it’s that okay I use this one-for-all command for “real” app? Or should I just ignore this command completely and write everything manually?

Thank you in advance for any help you can provide :slight_smile:


I may be misquoting someone by proxy here, but I remember someone saying that @chrismccord , at least, saw the generators as teaching tools for people mostly.


It might be true, but having generator command for “real” productivity also very convenience. Instead of writing everything manually. Just my thought…


I have used the html generator for Production apps. it is ok if know you what is being generated and understand the code that is being generated.

for small CRUD apps the generator is a good thing.
that said , make your own.

go to your project /lib/deps/phoenix/mix and deconstruct the code from the task you want. And be rid of tedious repetitive tasks forever.


Adding some cents to it: a very unknown feature is the ability to override the templates for the generated models, views, controllers and templates. Which you can use at your favor, without the need to build your own generator.

If you look a little bit on the original phoenix generator code, you’ll find that phoenix generator looks up first for your app “priv/templates/phoenix.gen.html” directory to get the templates, and if it does not exist, it looks to their own. You can get the default generated code on the same directory in the phoenix project.


Yeah it was months before I discovered that, it needs to be documented better! :smiley:


Well, since I’m just a new guy in elixir, this is quite a reliefs… Thanks!

Writing my own controller, model, etc seems much simpler :sweat_smile:
Thank you :slight_smile:

Could not agree more

nice, thanks for the heads up on that one.

1 Like

Sorry, looking to my answer, it really seemed like a very difficult thing to do. What I was saying is that, you can create a file priv/templates/phoenix.gen.html/controller.ex and this file will be used to generate the controller in the task mix phoenix.gen.html.

You can see the files in this folder for an example of which templates you can edit this way.

1 Like

I`m fairly new to elixir myself(2-3 months or so). I have 6 tiny apps in production at the moment. All of them have either used the phoenix scaffolding or Ex_admin.


Wow, looks like a lot simpler than I thought :smile:
I’ll try it asap, thanks again @kelvinst !

What kind of apps did you write? If I may know it.

1 Like

I have a have the following elixir applications:

  1. a small ordering system for a diner. so that the chefs can just work and make sure food goes to the right table every time
  2. Inventory system for a self serve tire warehouse
  3. small planning system for farms. never forget when that cow need a medical checkup etc
  4. Economics software for non profit organisations and sports teams
  5. maintenance scheduler for a workshop with options of telling you when you need to reorder supplies
  6. Logistics management system. I guess this one cant be called tiny anymore. Handles packaging and shipment of crates and everything around that.

All of them are deployed on local machines. the ordering system and logistics app will be combined into one app for food delivery services soon so i guess that would be the seventh.

1 Like