在Rails中使用液体3
我正在制作一个Rails博客引擎用于学习目的。 我想用液体作为模板引擎。 我有类似的东西
## posts_controller.rb ... def index @posts = Post.all end ... ## posts/index.html.liquid {% for post in posts do %} {{ post.title }} {% endfor %}
这给了我以下错误:
undefined local variable or method `template' for #
我已经在初始化器/ liquid.rb中加载了LiquidView。请让我知道我的问题是什么。 谢谢
据我所知,你应该有属性的液体方法(在你的情况下为’标题’)。 尝试这样的事情
class Post < ActiveRecord::Base liquid_methods :title end
并看到。
如果没有尝试使Liquid :: DropinheritancePost类
喜欢
class Posts < Liquid::Drop end
** BTW,因为您收到错误声明缺少模板变量,请确保您的液体渲染部分如下所示
(直接从液体doc复制)
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template @template.render( 'name' => 'tobi' ) # Renders the output => "hi tobi"
希望这可以帮助
干杯
sameera