how to lock the destroy action?

37 views
Skip to first unread message

Psycho Shine

unread,
Dec 17, 2014, 10:03:15 AM12/17/14
to rubyonra...@googlegroups.com
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?

Vivek Sampara

unread,
Dec 17, 2014, 10:11:57 AM12/17/14
to rubyonra...@googlegroups.com
Validate the destroy action in the ticket model . More info Here

--
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 rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3ede9e38-d33e-474e-9790-4ad663de5f94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vivek Sampara

unread,
Dec 17, 2014, 10:16:26 AM12/17/14
to rubyonra...@googlegroups.com
You could also use rails callbacks before_destroy 


before_destroy :check_bus_status

private
def check_bus_status
  return false if bus.tickets > bus.places*0.9
end

Psycho Shine

unread,
Dec 17, 2014, 10:22:27 AM12/17/14
to rubyonra...@googlegroups.com
thank so much. again)

среда, 17 декабря 2014 г., 7:16:26 UTC-8 пользователь Vivek Sampara написал:

Colin Law

unread,
Dec 17, 2014, 11:49:32 AM12/17/14
to rubyonra...@googlegroups.com
On 17 December 2014 at 15:03, Psycho Shine <annd...@gmail.com> wrote:
> hi all.
> Bus and Tickets/has_one, belongs_to/

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

Colin

> 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?
>
Reply all
Reply to author
Forward
0 new messages