我正在制作一个 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
#<PostsController:0x103d16290>
我已经在initializers/liquid.rb中加载了LiquidView
请让我知道我的问题是什么。
谢谢
据我所知,您应该对属性有液体方法(在您的情况下是“标题”)。尝试这样的事情
class Post < ActiveRecord::Base
liquid_methods :title
end
看看吧。
如果没有尝试让 Post 类被 Liquid::Drop 继承
like
class Posts < Liquid::Drop
end
** 顺便说一句,因为您收到一个错误,声称缺少模板变量,请确保您的液体渲染部分如下
(直接从液体文档复制)
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
@template.render( 'name' => 'tobi' ) # Renders the output => "hi tobi"
希望这可以帮助
cheers
sameera
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)