在 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
#<PostsController:0x103d16290>
我已经在initializers/liquid.rb中加载了LiquidView 请让我知道我的问题是什么。 谢谢
Im making a Rails blog engine for learning purpose. I want to use liquid as template engine. I have something like this
## posts_controller.rb
...
def index
@posts = Post.all
end
...
## posts/index.html.liquid
{% for post in posts do %}
{{ post.title }}
{% endfor %}
That gave me the following error:
undefined local variable or method `template' for
#<PostsController:0x103d16290>
I already had LiquidView loaded in initializers/liquid.rb
Please let me know what is my problem.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您应该对属性有液体方法(在您的情况下是“标题”)。尝试这样的事情
看看。
如果不尝试让 Post 类被 Liquid::Drop 继承,
就像
** 顺便说一句,因为你收到一个错误,声称缺少模板变量,请确保你的液体渲染部分如下
(直接从液体文档复制)
希望这有助于
欢呼
Sameera
As I know you should have liquid methods for attributes (in your case for 'title'). try something like this
and see.
If not try to make Post class inherited by Liquid::Drop
like
** BTW since you get an error claiming missing template variable make sure your liquid rendering part is as follows
(directly copied from liquid doc)
hope this helps
cheers
sameera