Rails 查询输出行#1,然后继续行#3

问题描述 投票:0回答:1

第 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 行查询

ruby-on-rails ruby haml
1个回答
0
投票

使用指数:

- @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
© www.soinside.com 2019 - 2024. All rights reserved.