【问题标题】:Unable to generate html in Phoenix 1.3无法在 Phoenix 1.3 中生成 html
【发布时间】:2018-05-10 01:03:32
【问题描述】:

尝试生成:

$ mix phx.gen.html MyModel my_models a b c d:integer

还有错误:

  ** (Mix) Expected the schema, "my_models", to be a valid module name

  mix phx.gen.html, phx.gen.json and phx.gen.context expect a
  context module name, followed by singular and plural names of
  the generated resource, ending with any number of attributes.
  For example:

      mix phx.gen.html Accounts User users name:string
      mix phx.gen.json Accounts User users name:string
      mix phx.gen.context Accounts User users name:string

  The context serves as the API boundary for the given resource.
  Multiple resources may belong to a context and a resource may be
  split over distinct contexts (such as Accounts.User and Payments.User).

这也不起作用:

$ mix phx.gen.html MyModel my_models a b c d:integer --no-context

$ mix phx.gen.html MyModel my_models a b c d:integer --no-context --no-schema

即使在此之后,错误仍然存​​在:

config :my_app, :generators,
    context: false

这是怎么回事?

【问题讨论】:

标签: elixir phoenix-framework


【解决方案1】:

来自phx.gen.html上的文档:

在没有架构或上下文文件的情况下生成

在某些情况下,您可能希望对 HTML 模板、控制器、 和控制器测试,但保留上下文的内部实现 或自己的架构。您可以使用 --no-context 和 --no-schema 用于文件生成控制的标志。

--no-context 标志指示生成器将上下文模块的实现留给开发人员,但您仍然需要在命令中包含上下文模块的名称,如下所示:

mix phx.gen.html MyContext MyModel my_models a b c d:integer --no-context

【讨论】:

  • 看我问题的最后一部分
  • 我同意如果您习惯于其他框架会有点混乱,但这是设计决定,您可以查找 here。此外,如果您想要旧的行为,您可以使用phoenix.gen.html 作为回答here
【解决方案2】:

为了让上面的答案更清楚一点,

mix phx.gen.html Thebindingcontext MyModel mymodels a b c d:integer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 2018-08-24
    • 1970-01-01
    相关资源
    最近更新 更多