首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用中间人生成特征帖子

使用中间人生成特征帖子
EN

Stack Overflow用户
提问于 2015-12-11 14:28:26
回答 1查看 102关注 0票数 0

我正试图在我的主页上为有特色的文章(如Wordpress中的文章)创建一个部分,我将featured: true放在文章的前端,然后我尝试使用以下方法生成文章:

Article.md

代码语言:javascript
复制
---
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 article

index.html.erb

代码语言:javascript
复制
<% 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]和其他变体,但没有骰子。

我有办法做到这一点吗?

EN

回答 1

Stack Overflow用户

发布于 2015-12-13 11:13:43

这已经只显示了featured = true的结果

代码语言:javascript
复制
<% 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 %>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34225816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档