osem-fcy/app/models/sponsor.rb

46 lines
1.2 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-28 15:24:51 +03:00
serialize :swag, Hash
serialize :swag_transportation, Hash
serialize :responsibe, Hash
2017-08-27 23:40:32 +03:00
2017-08-28 15:24:51 +03:00
attr_accessor :type, :quantity, :swag_index, :carrier_index,
:carrier_name, :tracking_number, :boxes,
:responsible_name, :responsible_email
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-29 12:04:31 +03:00
scope :contacted, -> { where(state: 'contacted') }
2017-08-27 15:42:52 +03:00
2017-08-29 12:04:31 +03:00
state_machine initial: :to_contact do
state :to_contact
2017-08-27 15:42:52 +03:00
state :confirmed
2017-08-29 12:04:31 +03:00
state :contacted
2017-08-27 15:42:52 +03:00
event :confirm do
2017-08-29 12:04:31 +03:00
transitions to: :confirmed, from: [:to_contact, :contacted]
2017-08-27 15:42:52 +03:00
end
event :cancel do
2017-08-29 12:04:31 +03:00
transitions to: :to_contact, from: [:confirmed, :contacted]
end
event :contact do
transitions to: :contacted, from: [:to_contact]
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