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处理程序的原因。最简单的方法可能是对注销人员进行猴子补丁并取消注册。 –