我理解你说的代码的意思了，感谢

On 2013-8-12, at 下午4:47, Ian Yang <notifications@github.com> wrote:

> In app/models/event_order.rb:
> 
> > @@ -4,6 +4,15 @@ class EventOrder < ActiveRecord::Base
> >    has_many :items, class_name: 'EventOrderItem', foreign_key: "order_id"
> >    priceable :price
> >  
> > +  validates :event_id, :user_id, :presence => true
> > +  validate do
> > +    # order_quantity = self.items.inject(0) { |sum, i| sum + i.quantity }
> > +    order_quantity = self.quantity || 0
> > +    if event.tickets_quantity == 0 || order_quantity > event.tickets_quantity
> 最后一张票，A 和 B 同时下单，都通过了验证，然后更新数量，然后减成-1了。
> 
> —
> Reply to this email directly or view it on GitHub.
>