how to lock the destroy action?

hi all.
Bus and Tickets/has_one, belongs_to/

Users and Tickets/has_many, belongs_to/

i want to realize next action:

“ticket.destroy.lock” if bus.tickets > bus.places*0.9

#if bus full for 90 %, users cant destroy their tickets (or bus never go to race:))

How correct to realize this locking action?

Validate the destroy action in the ticket model . More info Here

You could also use rails callbacks before_destroy

http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

before_destroy :check_bus_status

private

def check_bus_status

return false if bus.tickets > bus.places*0.9

end

thank so much. again)

hi all.
Bus and Tickets/has_one, belongs_to/

Bus has_one ticket? I don't think you will make much profit!

Colin