如何显示“尚未输入任何内容”?没有记录时的消息?

发布于 2024-11-14 12:05:04 字数 1344 浏览 2 评论 0原文

在我的应用程序中,我有场地记录,其中每个记录都可以有很多照片和评论。

当没有照片或评论时,如何显示“尚未输入任何内容”消息?

以下是我目前显示它们的方式:

评论

  <div id="reviews">
    <%= render :partial => 'reviews/review', :collection => @venue.reviews %>
  </div>

照片(使用彩盒显示)

  <div class="venue_photos_container">
    <div class="ppy4" id="ppy4">
      <ul class="ppy-imglist">
        <% for venuephoto in @venue.venuephotos %>
          <li class="venue_photo_thumb_container"><%= link_to image_tag(venuephoto.venuephoto.url(:image_scroller), :class => "venue_photo"), venuephoto.venuephoto.url(:large), :rel => "venue_photo_colorbox" %></li>
        <% end %>
      </ul>
      <div class="ppy-outer">
        <div class="ppy-stage">
          <div class="ppy-nav">
            <a class="ppy-prev" title="Previous image">Previous image</a>
            <a class="ppy-switch-enlarge" title="Enlarge">Enlarge</a>
            <a class="ppy-switch-compact" title="Close">Close</a>
            <a class="ppy-next" title="Next image">Next image</a>
          </div>
        </div>
      </div>
    </div>
  </div>

感谢您的任何帮助,非常感谢!

In my app I have venue records where each one can have many photos and reviews.

How can I go about displaying a 'nothing entered yet' message where the photos or reviews should be displayed when there isn't any?

Heres how I'm currently displaying them:

Review

  <div id="reviews">
    <%= render :partial => 'reviews/review', :collection => @venue.reviews %>
  </div>

Photos (displayed using colorbox)

  <div class="venue_photos_container">
    <div class="ppy4" id="ppy4">
      <ul class="ppy-imglist">
        <% for venuephoto in @venue.venuephotos %>
          <li class="venue_photo_thumb_container"><%= link_to image_tag(venuephoto.venuephoto.url(:image_scroller), :class => "venue_photo"), venuephoto.venuephoto.url(:large), :rel => "venue_photo_colorbox" %></li>
        <% end %>
      </ul>
      <div class="ppy-outer">
        <div class="ppy-stage">
          <div class="ppy-nav">
            <a class="ppy-prev" title="Previous image">Previous image</a>
            <a class="ppy-switch-enlarge" title="Enlarge">Enlarge</a>
            <a class="ppy-switch-compact" title="Close">Close</a>
            <a class="ppy-next" title="Next image">Next image</a>
          </div>
        </div>
      </div>
    </div>
  </div>

Thanks for any help its much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

表情可笑 2024-11-21 12:05:04

我会计算场地照片并通过条件语句进行计数。如果为零则显示“无图片”,否则显示照片。

<div class="venue_photos_container">
  <div class="ppy4" id="ppy4">
    <% if @venue.venuephotos.count.zero? %>
      Sorry, no pictures!
    <% else %>
      <ul class="ppy-imglist">
        <% for venuephoto in @venue.venuephotos %>
          <li class="venue_photo_thumb_container"><%= link_to image_tag(venuephoto.venuephoto.url(:image_scroller), :class => "venue_photo"), venuephoto.venuephoto.url(:large), :rel => "venue_photo_colorbox" %></li>
        <% end %>
      </ul>
      <div class="ppy-outer">
        <div class="ppy-stage">
          <div class="ppy-nav">
            <a class="ppy-prev" title="Previous image">Previous image</a>
            <a class="ppy-switch-enlarge" title="Enlarge">Enlarge</a>
            <a class="ppy-switch-compact" title="Close">Close</a>
            <a class="ppy-next" title="Next image">Next image</a>
          </div>
        </div>
      </div>
    <% end %>
  </div>
</div>

只是免责声明,此代码演示了基本思想,但我使用 HAML,因此此 ERB 可能不完全正确。

I would count the venue photos and run the count through a conditional statement. If it's zero display "no pics" otherwise display the photos.

<div class="venue_photos_container">
  <div class="ppy4" id="ppy4">
    <% if @venue.venuephotos.count.zero? %>
      Sorry, no pictures!
    <% else %>
      <ul class="ppy-imglist">
        <% for venuephoto in @venue.venuephotos %>
          <li class="venue_photo_thumb_container"><%= link_to image_tag(venuephoto.venuephoto.url(:image_scroller), :class => "venue_photo"), venuephoto.venuephoto.url(:large), :rel => "venue_photo_colorbox" %></li>
        <% end %>
      </ul>
      <div class="ppy-outer">
        <div class="ppy-stage">
          <div class="ppy-nav">
            <a class="ppy-prev" title="Previous image">Previous image</a>
            <a class="ppy-switch-enlarge" title="Enlarge">Enlarge</a>
            <a class="ppy-switch-compact" title="Close">Close</a>
            <a class="ppy-next" title="Next image">Next image</a>
          </div>
        </div>
      </div>
    <% end %>
  </div>
</div>

Just a disclaimer, this code demonstrates the basic idea but I use HAML so this ERB may not be exactly correct.

沙沙粒小 2024-11-21 12:05:04

我这样做的另一种方法可以防止我的视图中出现 if/then 逻辑:

在 Venue.rb 中:

class Venue
  def photo_state
    venuephotos.count > 0 ? 'with_photos' : 'without_photos'
  end
end

在 show.html.erb 中:

<%= render("venue_#{photo_state}" %>

在 _venue_with_photos.html.erb 中:

<ul class="ppy-imglist">
  <%= render @venue.venuephotos %>
</ul>

在 _venue_without_photos.html.erb 中:

Sorry, no pictures!

在 _venuephoto 中.html.erb

<li class="venue_photo_thumb_container"><%= link_to image_tag ... %></li>

是的,有点痴迷,但我喜欢尽可能在我的视图中除了“渲染”之外没有任何代码。这完全取决于您是否喜欢将所有代码放在一个文件中,还是将每一部分分解为易于理解的块。一个偏好的事情 - 没有真正的正确答案。

An alternate way that I do this that keeps me from having if/then logic in my views is this:

In Venue.rb:

class Venue
  def photo_state
    venuephotos.count > 0 ? 'with_photos' : 'without_photos'
  end
end

In show.html.erb:

<%= render("venue_#{photo_state}" %>

In _venue_with_photos.html.erb:

<ul class="ppy-imglist">
  <%= render @venue.venuephotos %>
</ul>

In _venue_without_photos.html.erb:

Sorry, no pictures!

In _venuephoto.html.erb

<li class="venue_photo_thumb_container"><%= link_to image_tag ... %></li>

Yes, a bit obsessive, but I like having no code except "render" in my views whenever possible. It's all in whether you like all your code in one file or each piece broken out in easy-to-digest chunks. A preference thing - no real right answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文