我正在开发一个带有命名空间(管理部分)的应用程序。是否有不创建 2 个 Controller 的 DRY 解决方案?因为我需要创建一个公共(public)用户 Controller 和一个管理员用户 Controller 来管理用户。
最佳答案
继承用户 Controller 怎么样?我自己使用它(用于图像),它非常适合我:
# file: apps/controllers/images_controller.rb
class ImagesController < ApplicationController
# image code (to show the image for example)
end
# file: apps/controllers/admin/images_controller.rb
class Admin::ImagesCOntroller < ImagesController
# additional admin code (to delete the image for example)
end
关于ruby-on-rails - 在 rails 中使用命名空间时使用双 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6987855/