Move logic to model

This commit is contained in:
Benjamin Cousaert 2014-12-08 11:41:38 +01:00
parent 5efef27454
commit b9e42b8bc1
2 changed files with 5 additions and 1 deletions

View file

@ -22,4 +22,8 @@ class Product < ActiveRecord::Base
validates :purchase_price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :sale_price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
def count(order)
order_products.find_by(order: order).count
end
end

View file

@ -1,5 +1,5 @@
<p>
<% order.products.each do |p| %>
<%= p.order_products.find_by(order: order).count.to_s + " " + p.name %>
<%= p.count(order).to_s + " " + p.name %>
<% end %>
</p>