Rails HAML engine rendering

扶醉桌前 提交于 2019-12-23 18:51:55

问题


What is wrong here?

Haml::Engine.new('= image_tag("golfer.png")').render

image_tag is always undefined (ActionView::Helpers in not loaded). How can I fix that? Thx!


回答1:


I think I found the solution.

  class TagHelper
    include Singleton
    include ActionView::Helpers::TagHelper
    include ActionView::Helpers::AssetTagHelper
  end

  puts Haml::Engine.new('= image_tag("golfer.png")').render(TagHelper.instance)


来源:https://stackoverflow.com/questions/4097642/rails-haml-engine-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!