-
-
Notifications
You must be signed in to change notification settings - Fork 91
Description
Code of Conduct
- I agree to follow this project's Code of Conduct
AI Policy
- I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.
Is your feature request related to a problem? Please describe.
I'm trying to generate a resource route set with a dash in it like <app-root>/random-thing/...
When I generate a controller + templates:
mix ash_phoenix.gen.html MyApp.Domain MyApp.Domain.RandomThing --resource-plural random_things
I will get valid code (AFAIK elixir identifiers can't have dashes, so underscore is the way to go here). The notice after the command runs describes how to add resource routing. The problem is that if I set up routes with:
# in /lib/praxis_web/router.ex
scope "/", PraxisWeb do
pipe_through :browser
resources "/random-things", RandomThingController
end
then the routing table won't match the generated templates.
Describe the solution you'd like
The ash_phoenix.gen.html
task already has an argument to help create an identifier in controller code:
ash_phoenix/lib/ash_phoenix/gen/gen.ex
Line 13 in 85fd465
- `--resource-plural` - The plural resource name (e.g. "products") |
If an optional parameter was added like --resource-plural-for-template
(when present) it could override the href
values in generated templates. Continuing with the example:
mix ash_phoenix.gen.html MyApp.Domain MyApp.Domain.RandomThing \
--resource-plural random_things \
--resource-plural-for-template random-things
Then when the dashed route prefix is added to the router there's no conflict, and the templates don't have to be updated by hand.
Describe alternatives you've considered
The obvious alternative is to accept the defaults but it should be possible to support both use cases. You might also imagine cases where (for some reason) a developer doesn't want the route prefix to match the resource name.
Maybe there would be a way to pass some argument to the resources
declaration in the router so it would pass a prefix into the template which would get substituted into the href
? I don't have enough expertise to say how viable that would be. I can see that the resources
declaration (which is part of Phoenix) has some parameters like alias
and as
, but this mix task is part of ash_phoenix
so it might take some co-ordination to make something like that work.
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status