【发布时间】:2016-03-16 18:03:09
【问题描述】:
我有一个 Rails 项目,它有一个 api 部分和一个常规部分。他们有一些常用的方法,例如,我有两个这样的控制器:
class PlacementController < ApplicationSafeController
def zip
file = ZipService::ZipGenerator.create_zip
send_data(file.read, type: 'application/zip')
File.delete(file.path)
end
end
和
class Api::ZipsController < ApiController
def single_zip
file = ZipService::ZipGenerator.create_zip
send_data(file.read, type: 'application/zip')
File.delete(file.path)
end
end
我的ApiController 和ApplicationSafeController 都继承自ApplicationController。我的问题是,在不使根 ApplicationController 变脏的情况下清理它的最佳方法是什么? (通过在那里添加一个新方法)。谢谢!
【问题讨论】:
标签: ruby-on-rails ruby api dry