Move logic to model
This commit is contained in:
parent
5efef27454
commit
b9e42b8bc1
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue