diff --git a/app/models/option.rb b/app/models/option.rb index 87dfc46..6d2eb25 100644 --- a/app/models/option.rb +++ b/app/models/option.rb @@ -1,15 +1,19 @@ class Option < ActiveRecord::Base - #associations between tables - belongs_to :question + #associations between tables + belongs_to :question has_many :option_warnings, :dependent => :destroy - + has_and_belongs_to_many :answers, join_table: "answers_options" - attr_accessible :text, :question_id, :is_default, :number, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :text, :question_id, :is_default, :number, :question, + :option_warnings, :answers, :as => [:default, :admin] - def to_s - "#{text}" - end + validates :question, :text, :number, presence: true + + def to_s + "#{text}" + end end \ No newline at end of file diff --git a/app/models/option_warning.rb b/app/models/option_warning.rb index d67709f..dfcbff4 100644 --- a/app/models/option_warning.rb +++ b/app/models/option_warning.rb @@ -1,12 +1,16 @@ class OptionWarning < ActiveRecord::Base - #associations between tables - belongs_to :option - belongs_to :organisation - - attr_accessible :text, :option_id, :organisation_id, :as => [:default, :admin] + #associations between tables + belongs_to :option + belongs_to :organisation - def to_s - "#{text}" - end +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :text, :option_id, :organisation_id, + :organisation, :option, :as => [:default, :admin] + + validates :organisation, :option, :text, presence: true + + def to_s + "#{text}" + end end \ No newline at end of file