也許有更好的方法來做到這一點。我想能夠動態加載一些路由。我打算在routes.rb
有靜態路線,custom_routes.rb
有自定義路線。然後在routes.rb
底部,我會做:僅當文件存在時才需要文件
CustomRoutes.create if defined?(CustomRoutes)
爲了這個工作,我有權要求custom_routes.rb
只有當該文件存在,但如何?
custom_routes.rb
class CustomRoutes
def self.create
MyApplication.routes.draw do
#...more routes here
end
end
end
謝謝,這是有效的。 –