第 1 行仅输出 1 条记录,在第 3 行继续其余部分
- if @local_news.present?
%h4.homepage-heading
.row#local_news
- @local_news.each do |news|
.col-sm-12
= render 'news_article', article: news, length: 160
%hr
第 2 行
- if @local_ads.present?
%h4.homepage-heading
.row#local_ads
- @local_ads.each do |ads|
.col-sm-12
= render 'ad'
%hr
第 3 行继续从第 1 行查询
使用指数:
- @local_news.each_with_index do |news, i|
- if i == 1
- if @local_ads.present?
%h4.homepage-heading
.row#local_ads
- @local_ads.each do |ad|
.col-sm-12
= render ad
%hr
- else
%h4.homepage-heading
.row#local_news
- news.each do |article|
.col-sm-12
= render 'news_article', article: article, length: 160
%hr