Liquid 插件错误:“form_for 未定义”
我在我的应用程序中使用液体插件。
在使用诸如 form_for
、check_box_tag
之类的 Rails 辅助方法时,我收到 错误 form_for not Define
..
有谁知道如何使用 Rails 辅助方法通过液体插件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不久前刚刚处理过这个问题 - 如果您想更好地了解如何扩展普通过滤器(包括您可能需要的辅助方法),我发现这个 Railscast 非常有帮助: http://railscasts.com/episodes/118-liquid
基本上,您需要设置自己的过滤器文件并包含帮助程序您想要使用的模块,然后添加使用该帮助器的方法(过滤器)。 这并不难,只需一秒钟即可设置。 在 Ryan 的示例中,他在 lib 中设置了一个名为 LiquidFilters 的模块,包括他想要的数字助手,并将其设置为使用货币过滤器,如下所示:
然后您所要做的就是记住何时解析要添加的液体内容:过滤器 => [LiquidFilters](获取您想要使用的过滤器模块的数组),它应该自动选择它。 此方法还确保如果您想要设置更多自定义过滤器或修改辅助过滤器,您可以轻松直观地执行此操作。
I was just dealing with this not too long ago - if you want a better understanding of what it takes to extend the normal filters (including helper methods you may want) I found this Railscast very helpful: http://railscasts.com/episodes/118-liquid
Basically, you'll need to set up your own filter file and include the helper modules you want to use, then add a method (filter) which uses that helper. It's not hard, just takes a second to setup. In Ryan's example he sets up a module in lib called LiquidFilters, includes the number helper he wanted and set it up to use a currency filter like so:
Then all you have to do is remember when you're parsing the liquid content to add :filters => [LiquidFilters] (takes an array of filter modules you want to use) and it should pick it up automatically. This method also makes sure that if you want to set up any more custom filters or modify the helper filters you have an easy and intuitive place to do that.
您可以直接使用html代码,例如,不使用link_to(不起作用!),在liquid模板中,您可以使用liquid标签编写html代码:
You can use directly html code, as instance, instead of use link_to (doesn't work!), inside the liquid template, you can write html code with liquid tags:
Liquid 有自己的助手,称为过滤器。 请参阅 https://github.com/Shopify/liquid/wiki/Liquid-for -设计师。
您可以决定在将值传递给 Liquid 之前应用帮助程序,也可以扩展 Liquid 注册您自己的过滤器(请参阅 https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers)。
如果您将 Liquid 注册为 Rails 模板处理程序,Liquid 会尝试使用您的助手作为过滤器。
但是,您需要使用 Liquid 语法。
不是
Liquid has its own helpers, called filters. See https://github.com/Shopify/liquid/wiki/Liquid-for-Designers.
You can either decide to apply the helper before passing the value to liquid or extend liquid registering your own filters (see https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers).
If you register liquid as Rails template handler, Liquid tries to use your helpers as filters.
However, you need to use the Liquid syntax.
Not
看一下 Liquid 的这个名为“Clots”的项目。 据说它解决了这个问题(我个人没有使用过它)。
http://github.com/ludicast/clots/tree/master
Take a look at this project for Liquid called "Clots". It supposedly addresses this issue (I haven't personally used it).
http://github.com/ludicast/clots/tree/master