Add 'week' column to TicketPurchases
This commit is contained in:
parent
9ff3601453
commit
c2184c1c4f
3 changed files with 26 additions and 1 deletions
|
|
@ -18,6 +18,8 @@ class TicketPurchase < ActiveRecord::Base
|
|||
scope :by_conference, ->(conference) { where(conference_id: conference.id) }
|
||||
scope :by_user, ->(user) { where(user_id: user.id) }
|
||||
|
||||
after_create :set_week
|
||||
|
||||
def self.purchase(conference, user, purchases)
|
||||
errors = []
|
||||
ActiveRecord::Base.transaction do
|
||||
|
|
@ -59,3 +61,10 @@ class TicketPurchase < ActiveRecord::Base
|
|||
purchase
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_week
|
||||
self.week = created_at.strftime('%W')
|
||||
save!
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue