سؤال

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?

هل كانت مفيدة؟

المحلول

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).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top