1
A
回答
5
據我所見,有沒有辦法unregister
模板處理程序。
但是我們可以通過黑客來實現。
ActionView::Template::Handlers::ERB
有以下幾行;
self.class.erb_implementation.new(
erb,
:trim => (self.class.erb_trim_mode == "-")
).src
因此,讓我們打破它,爲樂趣。
我們將添加一個初始config/initializers/no_erb_allowed.rb
class NoErbAllowed
def initialize(*args)
raise "ERB is not allowed"
end
end
ActionView::Template::Handlers::ERB.erb_implementation = NoErbAllowed
任何試圖使用,然後再培訓局會引發錯誤
ActionView::Template::Error (ERB is not allowed):
1
我認爲這應該工作的任何觀點:
handlers = ActionView::Template::Handlers.class_variable_get :@@template_handlers
handlers.delete :erb
ActionView::Template::Handlers.class_variable_set :@@template_handlers, handlers
基本上這得到@@template_handlers
散列從ActionView::Template::Handlers
,刪除:erb
鍵(指向ERB處理程序)並將其寫回該類。
這可能會在initializer。它需要ActionView::Template::Handlers
(顯然)之後加載,但自己加載的處理程序之前,所以我覺得它屬於在to_prepare
或before_eager_load
初始化,例如:
module YourApp
class Application < Rails::Application
config.before_eager_load do
handlers = ActionView::Template::Handlers.class_variable_get :@@template_handlers
handlers.delete :erb
ActionView::Template::Handlers.class_variable_set :@@template_handlers, handlers
end
end
end
希望這是有幫助!
相關問題
- 1. Rails處理.Erb與Nils
- 2. 在Rails應用程序中處理程序的奇怪行爲
- 3. Rails erb預處理沒有在開發模式中發生
- 4. 禁用處理程序運行
- 5. 如何在non rails應用程序中實現erb partials?
- 6. 如何在MFC中啓用或禁用事件處理程序?
- 7. 在Javascript中啓用/禁用按鈕單擊處理程序
- 8. 在Razor中禁用並啓用事件處理程序
- 9. 在Visual Studio基於MFC的應用程序中禁用事件處理程序
- 10. 在Rails 3.1應用程序中處理不存在的路線
- 11. 爲什麼禁用onClick處理程序時禁用true?
- 12. Ansible - 預處理ERB模板
- 13. 如何在Ruby On Rails應用程序中處理Thumbs.db文件
- 14. bootstrap-confiirmation不處理方法:在rails應用程序中刪除
- 15. 如何在rails應用程序中處理肥皂數據?
- 16. 如何處理在rails應用程序中輸入時間
- 17. 在Rails應用程序中處理寶石
- 18. 發送和處理.json請求(在Rails應用程序中)
- 19. 在rails應用程序中處理價格和貨幣
- 20. PushButton處理程序在禁用 - >啓用GWT後禁用 - >啓用
- 21. 在Rails郵件程序中包含ERB主題行
- 22. 我可以禁用進程的未處理異常處理程序嗎?
- 23. 在Ruby on Rails中使用erb內部erb
- 24. 在中斷處理程序
- 25. 在Rails應用程序中整理JavaScript
- 26. 事件在Java中使用通用處理程序處理
- 27. 禁用記錄器,如果沒有處理程序存在
- 28. 在Fortran運行時禁用FPE處理程序
- 29. 禁用事件處理程序在c#上textchanged
- 30. 實現Rails 3模板處理程序
我會先在ActionView :: Template :: Handlers中戳一下;這是註冊erb處理程序的原因。最簡單的方法可能是對註銷人員進行猴子補丁並取消註冊。 –