Correct way to use Phoenix 1.3 Generators

What is the correct way or the best practice for generating HTML and JSON views for the same resource?

If I have a blog context, and I use the HTML generator like this:

mix phx.gen.html Blogs Post posts body:text user_id:references:users

And then later I wanted a JSON version I was thinking I would do this:

mix phx.gen.json Blogs Post posts body:text user_id:references:users

But doing so results in error messages like this:

The following files conflict with new files to be generated:

See the --web option to namespace similarly named resources

What’s the --web option? I can’t quite figure out where to pass it.

If anyone has any advice on how to generate both HTML and JSON for the same resource that’d be greatly appreciated.

Thanks in advance.

1 Like

Well, documentation tells this:

mix help phx.gen.json | grep -C5 -- --web
    mix phx.gen.html Sales User users --context-app warehouse

## Web namespace

By default, the controller and view will be namespaced by the schema name.
You can customize the web module namespace by passing the `--web` flag with a
module name, for example:

    mix phx.gen.html Sales User users --web Sales

Which would geneate a `lib/app_web/controllers/sales/user_controller.ex` and

## Generating without a schema or context file

Thats at least how you can get more information about that --web option. I’m not quite sure if it helps though :wink:


Good sir, that was totally helpful and exactly what I needed to keep going.

Thank you for the clarifications!