我正试图在我的主页上为有特色的文章(如Wordpress中的文章)创建一个部分,我将featured: true放在文章的前端,然后我尝试使用以下方法生成文章:
Article.md
---
title: Example Article
date: 2012-01-01
published: true
description: This is a very nice article you should read!
tags: example
featured: true
---
## This is the articleindex.html.erb
<% blog.articles.select {|a| a.data[:featured] }.each do |article| %>
<h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
<!-- use article.summary(250) if you have Nokogiri available to show just
the first 250 characters -->
<%= article.body %>
<% end %>我和if unless玩过,试着检查数据是否是真的,但我没有运气,我也尝试了[:featured => true]和其他变体,但没有骰子。
我有办法做到这一点吗?
发布于 2015-12-13 11:13:43
这已经只显示了featured = true的结果
<% blog.articles.select {|a| a.data[:featured] }.each do |article| %>
<h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
<!-- use article.summary(250) if you have Nokogiri available to show just
the first 250 characters -->
<%= article.body %>
<% end %>https://stackoverflow.com/questions/34225816
复制相似问题