added intervention controller and stuff

This commit is contained in:
Thomas Hille
2017-02-28 15:24:53 +01:00
parent 2456f46b2b
commit 3d7f5bdf1a
10 changed files with 141 additions and 8 deletions

View File

@ -1,15 +1,16 @@
class Intervention < ActiveRecord::Base
NAME = %w(overallSlower longSession syntaxErrors videoNotWatched)
has_many :user_exercise_interventions
has_many :users, through: :user_exercise_interventions, source_type: "ExternalUser"
#belongs_to :user, polymorphic: true
#belongs_to :external_users, source: :user, source_type: ExternalUser
#belongs_to :internal_users, source: :user, source_type: InternalUser, through: :user_interventions
# alias_method :users, :external_users
#has_many :exercises, through: :user_interventions
validates :name, inclusion: {in: NAME}
def to_s
name
end
def self.createDefaultInterventions
%w(BreakIntervention QuestionIntervention).each do |name|
Intervention.find_or_create_by(name: name)
end
end
end