在模块中声明控制器类的正确方法是什么?

时间:2013-12-05 13:59:02

标签: ruby-on-rails module controller

我有多个项目,我必须在模块中添加一个控制器,用于命名空间和不同的用户原因。阅读this question之后,我对这些差异有了更深入的了解,但并不真正知道哪一个最好。问题是我总是这样写:

# Version A: app/controllers/example_module/example_controller.rb
module ExampleModule
  class ExampleController < ExampleModuleBaseController
  end
end

# app/controllers/example_module/example_module_base_controller.rb
class ExampleModule::ExampleModuleBaseController < ApplicationController
end

当你跑步时:

rails g controller ExampleModule/Example

它创建:

# app/controllers/example_module/example_controller.rb
class ExampleModule::ExampleController < ApplicationController
end

在纠正继承后,它将是:

# Version B: app/controllers/example_module/example_controller.rb
class ExampleModule::ExampleController < ExampleModule::ExampleModuleBaseController
end

哪个版本是正确的?版本A或版本B?

0 个答案:

没有答案