Question

I created a custom Liquid filter

module LinkFilter
include ActionView::Helpers::UrlHelper
include Rails.application.routes.url_helpers

 def link(input,source)
  link_to input,source
 end
end

and placed it in app/filters/LinkFilter.rb

How do I globally register the filter? According the Liquid documentation, adding this line at the end of the above file would register it globally:

Liquid::Template.register_filter(LinkFilter)

But it doesn't seem to work. Am I placing the filter in the wrong location or what?

Était-ce utile?

La solution

You have to place the filter in the lib directory instead. The one in the application root, not the app/lib one (if you have one).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top