【问题标题】:Run Generate Controller command from a Module从模块运行生成控制器命令
【发布时间】:2013-06-17 17:24:13
【问题描述】:

我知道在 Rails 中创建控制器的基本命令是使用 Rails 生成控制器

但在代码中,我看到了类似下面的结构,想知道如何做到这一点?

结构如下:

生成的代码是这样的,我需要类似的东西:

module Performance
  class BaseController < ApplicationController
  end
end


module Performance
  class GroupsController < BaseController
    def show
    end

    def index
    end
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.2


    【解决方案1】:

    要生成命名空间控制器,您应该键入,例如:

    rails g controller performance/base
    

    【讨论】:

    • 好吧,我现在试过了,但它没有生成“模块”的东西,我说例如 rails g controller 父/子,它创建了一个名为父亲的目录,并在其中创建了一个 child_controller,但是该 child_controller 的源中没有“模块”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多