Rails 3:CacheHelper,缓存块不会在生产环境中渲染
我希望有人可以帮助我,因为我面临着关于 Rails 3 的这种奇怪行为。
问题是:
我开发了一个博客,其中每篇文章可能有一个或多个标签。 我使用经典方法为每篇文章分配标签,使用第三种模型:标记,它使用各自的 id 建立文章及其标签之间的桥梁。
然后,在我的文章的索引页中,我有一个显示所有标签的侧边栏。
到目前为止,开发环境中一切正常:所有标签都显示出来。但是...当我在生产环境中启动该站点时,根本没有标签出现,但它们确实保存在生产数据库中。
这是我在视图中使用的显示标签的代码:
<ul id="tags">
<% cache("all_tags") do %>
<% for tag in Tag.find(:all, :order => "name") %>
<li><%= link_to "#{tag.name}", tag_path(tag) %></li>
<% end %>
<% end %>
</ul>
另外,我也尝试过添加类似的内容
<%= Tag.all %>
,并且它似乎会为数据库中保存的每个标签产生一个奇怪的结果:
#<Tag:some_alpha_numeric_caracters>
有人知道这种奇怪的行为吗?
非常感谢您给我带来的所有帮助:)
问候, M·米勒
I hope that someone may help me because I'm facing such a strange behavior concerning Rails 3.
Here's the problem :
I've developed a blog in which each article may have one or more tags.
I used a classic method to assign tags to each article, using a third model: taggings which makes the bridge between an Article and its tags usign their respective ids.
Then, in the index page of my articles, I have a sidebar showing all the tags.
So far everything works well in the Development environment: all the tags show up. But... When I launch the site in a production environment, no tags appear at all but they do are saved in the production database.
Here's the code I use within my view to show up the tags:
<ul id="tags">
<% cache("all_tags") do %>
<% for tag in Tag.find(:all, :order => "name") %>
<li><%= link_to "#{tag.name}", tag_path(tag) %></li>
<% end %>
<% end %>
</ul>
Also I've tried to just put something like
<%= Tag.all %>
And it seems to produce a strange result for each tag saved in the database:
#<Tag:some_alpha_numeric_caracters>
Does anyone have an idea about this strange behavior?
Thanks a lot for all your help you may bring to me :)
Regards,
M. Millet
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我终于找到了问题。我不得不简单地删除:
似乎缓存包含的内容(使用缓存功能)没有在生产中呈现。但我不知道为什么......所以即使我已经解决了我的问题,如果有人能解释我为什么缓存块不在生产环境中呈现,那就太好了。
谢谢:)
最诚挚的问候,
库尔加尔。
Ok so I finally found the problem. I had to simply delete:
It seems that what the cache contains (usign the cache function) is not rendered in production. But I don't know why.. So even if I've resolved my problem it would be great if anyone can explain me why the cache block doesn't render in a production environment.
Thanks :)
Best regards,
Kulgar.