diff --git a/app/views/layout/_homepage.html.erb b/app/views/layout/_homepage.html.erb
index a238caba..423a1633 100644
--- a/app/views/layout/_homepage.html.erb
+++ b/app/views/layout/_homepage.html.erb
@@ -95,11 +95,13 @@
<% @all_galleries = Gallery.all %>
<% map = {} %>
<% @all_galleries.each do |gal| %>
- <% total = gal.reviews.sum(&:rating).to_i %>
- <% count = gal.reviews.size %>
+ <% total = gal.reviews.sum(&:rating).to_i if gal.reviews.present? %>
+ <% total ||= 0 %>
+ <% count = gal.reviews.size if gal.reviews.present? %>
+ <% count ||= 0 %>
<% gal.gallery_totalRate ||= total %>
<% gal.gallery_totalRator ||= count %>
- <% if map.size < 50 && (gal.gallery_totalRate / gal.gallery_totalRator >= 3) %>
+ <% if map.size < 50 && gal.gallery_totalRator > 0 && (gal.gallery_totalRate / gal.gallery_totalRator >= 3) %>
<% map[gal] = gal.gallery_totalRate / gal.gallery_totalRator %>
<% end %>
<% end %>