Is there a mix task to rename controllers in a Phoenix application?


Is there a mix task to rename a controller - the filename, the module name and the routes in router.ex?
If there isn’t, what do you normally do? Do you change it manually when you have to in all these places? I am trying to learn if there is a better way than doing this manually, or using find/replace in files.

Thank you.

The phoenix generators are called “generators” for a reason. They’re meant to get you started/up and running, but they’re not meant as a general purpose code maintenance tool. In my experience find/replace is rather simple to do on elixir, compared to the error rate I had in other languages. If you didn’t do many customizations an option might be to rerun the generators. The more code you added the less trivial it becomes to change this unknown code correctly as you asked for.

Find/replace is great for most things but I do find it tedious to rename a liveview or component, where besides renaming the module you have to rename the colocated .heex or .sface file to have the snakecase version of the module name (and usually the module .ex to match), so that’s 3 operations for one rename…

So sorry for not responding earlier. Thank you! I wanted to make sure I was not missing any clever way. I agree with @mayel though. Find/replace can be a little tedious because some names are in file names and some are variables and the case also differs. But perhaps, as you said, there is no way to do this reliably in an automated fashion.