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

On Wed, Dec 17, 2014 at 8:41 PM, Vivek Sampara <[email protected]>
wrote:
>
> Validate the destroy action in the ticket model . More info Here
> <http://stackoverflow.com/questions/123078/how-do-i-validate-on-destroy-in-rails>
>
> On Wed, Dec 17, 2014 at 8:33 PM, Psycho Shine <[email protected]> wrote:
>>
>> 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?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-talk/3ede9e38-d33e-474e-9790-4ad663de5f94%40googlegroups.com
>> <https://groups.google.com/d/msgid/rubyonrails-talk/3ede9e38-d33e-474e-9790-4ad663de5f94%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj97xSCfGUjKc81FuCm86LmZ%3DoX7-%3DyFR-afKSHYRVWjLQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to