How to include ActionView helpers in the assets pipeline?

前端 未结 2 1659
抹茶落季
抹茶落季 2020-12-05 20:27

How to include Rails view helpers to be accesible by assets pipeline execution context?

An example use case would be to generate the markup for a form, using

2条回答
  •  遥遥无期
    2020-12-05 21:20

    Create a inititializer and include the helpers in the context of the assets like this:

    Rails.application.assets.context_class.class_eval do
      include ActionView::Helpers
      include MyAppHelper
      include Rails.application.routes.url_helpers
    end
    

    Taken from this sprockets issue

提交回复
热议问题