Rails: How do I have a zero if there is no data? -


currently if user sells see box witha price. if haven't sold box disapears , see sales. how leave number $0 if user didn't sell instead of clear blank?

thanks

<% if current_user %>               <sold>                <li><%= link_to "sales", current_user %>               <% @sales.each |sale| %>             <div class="sold-count">$<%= sale.amount / 100 %></ %></div>  </li> </sold>         <% end %> 

right you're iterating on sales each sale, if size of container zero, loop going skipped.

you need add conditional check see if sales empty, @sales.empty? , if is, show 0.

<% if @sales.empty? %>     <div class="sold-count"> $0 </div>  </li> </sold> <% end %> 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -