osem-fcy/app/models/booth.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2017-05-17 13:31:27 +03:00
class Booth < ActiveRecord::Base
2017-06-18 23:33:54 +03:00
include ActiveRecord::Transitions
2017-05-17 13:31:27 +03:00
belongs_to :conference
has_many :booth_requests
has_many :users, through: :booth_requests
2017-06-06 21:36:18 +03:00
validates :title,
uniqueness: { case_sensitive: false },
2017-05-17 13:31:27 +03:00
presence: true
validates :description,
:reasoning,
:state,
:logo_link,
2017-05-17 13:31:27 +03:00
:conference_id,
presence: true
2017-06-18 23:33:54 +03:00
state_machine initial: :submitted do
state :submitted
state :withdrawn
state :to_accept
state :accepted
state :rejected
event :restart do
transitions to: :submitted, from: [:withdrawn]
end
event :withdrawn do
transitions to: :withdrawn, from: [:submitted, :to_accept, :accepted]
end
event :to_accept do
transitions to: :to_accept, from: [:submitted, :rejected, :accepted]
end
event :accept do
transitions to: :accepted, from: [:submitted, :to_accept]
end
event :reject do
transitions to: :rejected, from: [:submitted]
end
event :reset do
transitions to: :submitted, from: [:to_accept]
end
end
def transition_possible?(transition)
self.class.state_machine.events_for(current_state).include?(transition)
end
2017-05-17 13:31:27 +03:00
end