Search code examples
ruby-on-railsrecords

How can I display a 'nothing entered yet' message for when theres no records?


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!


Solution

  • 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.