I'm using Liquid markup in a Rails project that I'm working on, and I'm trying to create a link_to filter.
I'd like to be able to generate templates such as the following:
<ul>
{% for page in edition.pages %}
<li>{{page | link_to_page}}</li>
{% endfor %}
</ul>
Where I could use polymorphic routes to generate the link based on the object passed in.
module MyFilters
include ActionController::PolymorphicRoutes
def link_to_page page
ActionView::Helpers::UrlHelper.link_to page.name, polymorphic_path([page.edition, page])
end
end
This doesn't work. I understand why it doesn't work (Liquid creates a Drop class that substitutes for the real object), and the security model that requires that this sort of behavior NOT work by default. I was wondering if anyone had gotten something like this to work before, in a safe and stable way.
Is it possible to write my Drop classes from scratch, so that they will respond to the methods that polymorphic_path depends on? Or mix code into the Drop classes as they're generated dynamically?