osem-fcy/app/models/sponsor.rb

40 lines
1 KiB
Ruby
Raw Normal View History

2014-06-05 17:51:22 +05:30
class Sponsor < ActiveRecord::Base
2017-08-27 15:42:52 +03:00
include ActiveRecord::Transitions
2014-06-05 17:51:22 +05:30
belongs_to :sponsorship_level
belongs_to :conference
2017-08-26 20:41:36 +03:00
serialize :swags, Hash
2017-08-27 23:40:32 +03:00
serialize :courier_info, Hash
attr_accessor :type, :quantity, :swag_index, :courier_index,
:courier_name, :tracking_number, :boxes
2017-08-23 12:26:46 +03:00
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
2016-04-27 15:55:39 +02:00
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
2016-04-07 14:38:36 -06:00
validates :name, :website_url, :sponsorship_level, presence: true
2017-08-27 15:42:52 +03:00
scope :confirmed, -> { where(state: 'confirmed') }
2017-08-27 23:40:32 +03:00
scope :unconfirmed, -> { where(state: 'unconfirmed') }
2017-08-27 15:42:52 +03:00
2017-08-27 23:40:32 +03:00
state_machine initial: :unconfirmed do
state :unconfirmed
2017-08-27 15:42:52 +03:00
state :confirmed
event :confirm do
2017-08-27 23:40:32 +03:00
transitions to: :confirmed, from: [:unconfirmed]
2017-08-27 15:42:52 +03:00
end
event :cancel do
2017-08-27 23:40:32 +03:00
transitions to: :unconfirmed, from: [:confirmed]
2017-08-27 15:42:52 +03:00
end
end
def transition_possible?(transition)
self.class.state_machine.events_for(current_state).include?(transition)
end
2014-06-05 17:51:22 +05:30
end