ruby-on-rails - 在 rails 中使用命名空间时使用双 Controller ?

标签 ruby-on-rails ruby namespaces

我正在开发一个带有命名空间(管理部分)的应用程序。是否有不创建 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/

相关文章:

ruby-on-rails - Sidekiq 在其他作业完成后执行作业

jquery - RoR : jQuery jCrop, 在预览中无法正确裁剪

ruby-on-rails - 猴子修补设计(或任何 Rails gem)

xml - xml 中命名空间在属性上的范围

python - python 有类似 C++ 的 using 关键字吗?

ruby-on-rails - 无法使用 redis-rb gem 和公共(public)访问连接到集群 Azure Redis 缓存

arrays - 如何从 ruby​​ 中的哈希数组的范围中找到最小值?

Ruby 相当于 'which'

PHP命名空间从不同目录调用函数

ruby-on-rails - Rails Devise API - 登录路由响应 `You need to sign in or sign up before continuing.`