Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix phx.gen.html creates wrong subfolder and wrong module name #2405

Closed
dbulic opened this issue Jul 25, 2017 · 10 comments
Closed

mix phx.gen.html creates wrong subfolder and wrong module name #2405

dbulic opened this issue Jul 25, 2017 · 10 comments

Comments

@dbulic
Copy link

dbulic commented Jul 25, 2017

Environment

  • Elixir version (elixir -v): 1.4.5
  • Phoenix version (mix deps): 1.3.0-rc.3
  • NodeJS version (node -v): 8.2.1
  • NPM version (npm -v): 5.3.0
  • Operating system: Ubuntu 16.04
mix phx.new xx
mix ecto.create
mix phx.gen.html Web Movie movies name:string

Expected behavior

Expecting to see lib/xx/web folder. Expecting to find controller Xx.Web.MoviesController in lib/xx/web/controllers.
Expecting to see defmodule Xx.Web.MovieController do in lib/xx/web/controllers/movie_controller.ex

Actual behavior

Seeing both lib/xx and lib/xx_web folder. Being incorrectly instructed to:

Add the resource to your browser scope in lib/xx_web/router.ex:

    resources "/movies", MovieController

Folder xx_web doesn't contain router.ex, it's in xx folder.
Seeing defmodule XxWeb.MovieController do in lib/xx_web/controllers/movie_controller.ex

@PhillippOhlandt
Copy link

The Xx.Web namespace was changed to XxWeb in rc3, see https://elixirforum.com/t/phoenix-1-3-0-rc-3-released/7150/13

@dbulic
Copy link
Author

dbulic commented Jul 25, 2017

I see, thanks. I had to rerun mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez
Seems I had an old version that was slightly broken.

@dbulic dbulic closed this as completed Jul 25, 2017
@ghost
Copy link

ghost commented Jul 29, 2017

Phoenix newbie here. I'm confused, should it work as expected now? I'm following along the guide at https://hexdocs.pm/phoenix/testing.html#content with Phoenix 1.3.0 and I'm bumping into issues.

$ mix phx.new hello
$ cd hello
$ mix ecto.create
$ mix phoenix.gen.html User users name:string email:string bio:string number_of_pets:integer

Help message says to edit web/router.ex but I don't have such a file, it appears to be lib/hello_web/router.ex


$ vi lib/hello_web/router.ex
$ mix text
** (CompileError) test/controllers/user_controller_test.exs:2: module Hello.ConnCase is not loaded and could not be found                                               
    (elixir) expanding macro: Kernel.use/1                                          
    test/controllers/user_controller_test.exs:2: Hello.UserControllerTest (module)  
    (elixir) lib/code.ex:376: Code.require_file/2                                   
    (elixir) lib/kernel/parallel_require.ex:59: anonymous fn/2 in Kernel.ParallelRequire.spawn_requires/5 

Apparently that's because ConnCase is under HelloWeb, not under Hello. I tried to fix that in test/hello_web/controllers/page_controller_test.exs but then got this error

$ mix test
...** (CompileError) test/models/user_test.exs:2: module Hello.ModelCase is not loaded and could not be found
    (elixir) expanding macro: Kernel.use/1
    test/models/user_test.exs:2: Hello.UserTest (module)
    (elixir) lib/code.ex:376: Code.require_file/2
    (elixir) lib/kernel/parallel_require.ex:59: anonymous fn/2 in Kernel.ParallelRequire.spawn_requires/5

I found a Hello.DataCase module that looks like it might be what it's looking for so I edited test/models/user_test.exs to replace ModelCase with DataCase and now I get this error:

$ mix test               
...** (CompileError) test/controllers/user_controller_test.exs:30: Hello.User.__struct__/1 is undefined, cannot expand struct Hello.User                                
    test/controllers/user_controller_test.exs:29: (module)                          
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6      
``
And I got stuck on this one. Am I doing something wrong are there indeed issues with generated code?

@webdeb
Copy link
Contributor

webdeb commented Jul 29, 2017

@amarandon The following cannot work

$ mix phx.new hello
...
$ mix phoenix.gen.html

@ghost
Copy link

ghost commented Jul 29, 2017

@webdeb Of course, good catch! All tests passing now :)

I got this from section "Generating More Files" of https://hexdocs.pm/phoenix/testing.html#content
I guess I should send a PR to update this guide, shouldn't I?

@webdeb
Copy link
Contributor

webdeb commented Jul 29, 2017

@amarandon Sure, why not. this is the repo https://github.com/phoenixframework/phoenix_guides

@ghost
Copy link

ghost commented Jul 29, 2017

@webdeb OK, I noticed more problems in the guide so I added issue phoenixframework/phoenix_guides#721 and intend to work on it. Thanks for your help!

@roberthopman
Copy link

@webdeb why does this not work?
$ mix phx.new hello
...
$ mix phoenix.gen.html

@OvermindDL1
Copy link
Contributor

$ mix phoenix.gen.html

$ mix phx.gen.html

@PhillippOhlandt
Copy link

@roberthopman Because phx generates a Phoenix 1.3 app and phoenix are the generators for Phoenix 1.2 and below. The default project structure changed in Phoenix 1.3 and therefore the phoenix generators are not compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants