我使用了一些命名空間的控制器,也從一個父控制器繼承。在每個子類,我需要有(for anyone wondering why...):如何我從其父子類控制器的CONTROLLER_NAME?
class Fruits::ApplesController < FruitsController
# controller_name below is 'apples'
require_dependency "fruits/#{controller_name}"
...
end
所以,既然我寧願在我父類有require_dependency線一次我試圖將它移到FruitsController,但問題是,CONTROLLER_NAME現等於「水果」 ..
class FruitsController < ApplicationController
# controller_name is 'fruits' no matter which subclassed controller is called
require_dependency "fruits/#{controller_name}"
...
end
所以,我怎麼能正確地得到FruitsController子類的控制器name的值,這樣我可以保持這種require_dependency行了我的子類的? controller_path也沒有幫助。
謝謝!
感謝您的解釋@khelll – Carter 2011-02-14 01:35:30