如何显示“尚未输入任何内容”?没有记录时的消息?
在我的应用程序中,我有场地记录,其中每个记录都可以有很多照片和评论。
当没有照片或评论时,如何显示“尚未输入任何内容”消息?
以下是我目前显示它们的方式:
评论
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会计算场地照片并通过条件语句进行计数。如果为零则显示“无图片”,否则显示照片。
只是免责声明,此代码演示了基本思想,但我使用 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.
Just a disclaimer, this code demonstrates the basic idea but I use HAML so this ERB may not be exactly correct.
我这样做的另一种方法可以防止我的视图中出现 if/then 逻辑:
在 Venue.rb 中:
在 show.html.erb 中:
在 _venue_with_photos.html.erb 中:
在 _venue_without_photos.html.erb 中:
在 _venuephoto 中.html.erb
是的,有点痴迷,但我喜欢尽可能在我的视图中除了“渲染”之外没有任何代码。这完全取决于您是否喜欢将所有代码放在一个文件中,还是将每一部分分解为易于理解的块。一个偏好的事情 - 没有真正的正确答案。
An alternate way that I do this that keeps me from having if/then logic in my views is this:
In Venue.rb:
In show.html.erb:
In _venue_with_photos.html.erb:
In _venue_without_photos.html.erb:
In _venuephoto.html.erb
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.