Class: Answer
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Answer
- Defined in:
- app/models/answer.rb
Overview
Instance Attribute Summary collapse
-
#file ⇒ Object
Has_attached istance.
-
#value ⇒ String
Answer content.
Instance Method Summary collapse
-
#category ⇒ String
Delegated from Question#category.
-
#category_file? ⇒ String
Delegated from Question#category.
-
#category_select ⇒ String
Delegated from Question#category.
-
#options ⇒ Array
Delegated from Question.
-
#options_title ⇒ Object
List of valid option for value.
Instance Attribute Details
#file ⇒ Object
Returns has_attached istance.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/answer.rb', line 29 class Answer < ApplicationRecord belongs_to :ticket belongs_to :question has_one_attached :file delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true delegate :happening_id, to: :ticket, allow_nil: true, prefix: true delegate :attached?, to: :file, prefix: true validates :question, uniqueness: { scope: :ticket } validates :question_happening_id, comparison: { equal_to: :ticket_happening_id } validates :file, presence: true, if: :question_category_file? validates :value, absence: true, if: :question_category_file? validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file? validates :value, inclusion: { in: :options_title }, if: :question_category_select? # @return list of valid option for value def .acceptable.pluck :title end end |
#value ⇒ String
Returns answer content.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/answer.rb', line 29 class Answer < ApplicationRecord belongs_to :ticket belongs_to :question has_one_attached :file delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true delegate :happening_id, to: :ticket, allow_nil: true, prefix: true delegate :attached?, to: :file, prefix: true validates :question, uniqueness: { scope: :ticket } validates :question_happening_id, comparison: { equal_to: :ticket_happening_id } validates :file, presence: true, if: :question_category_file? validates :value, absence: true, if: :question_category_file? validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file? validates :value, inclusion: { in: :options_title }, if: :question_category_select? # @return list of valid option for value def .acceptable.pluck :title end end |
Instance Method Details
#category ⇒ String
Returns delegated from Question#category.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/answer.rb', line 29 class Answer < ApplicationRecord belongs_to :ticket belongs_to :question has_one_attached :file delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true delegate :happening_id, to: :ticket, allow_nil: true, prefix: true delegate :attached?, to: :file, prefix: true validates :question, uniqueness: { scope: :ticket } validates :question_happening_id, comparison: { equal_to: :ticket_happening_id } validates :file, presence: true, if: :question_category_file? validates :value, absence: true, if: :question_category_file? validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file? validates :value, inclusion: { in: :options_title }, if: :question_category_select? # @return list of valid option for value def .acceptable.pluck :title end end |
#category_file? ⇒ String
Returns delegated from Question#category.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/answer.rb', line 29 class Answer < ApplicationRecord belongs_to :ticket belongs_to :question has_one_attached :file delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true delegate :happening_id, to: :ticket, allow_nil: true, prefix: true delegate :attached?, to: :file, prefix: true validates :question, uniqueness: { scope: :ticket } validates :question_happening_id, comparison: { equal_to: :ticket_happening_id } validates :file, presence: true, if: :question_category_file? validates :value, absence: true, if: :question_category_file? validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file? validates :value, inclusion: { in: :options_title }, if: :question_category_select? # @return list of valid option for value def .acceptable.pluck :title end end |
#category_select ⇒ String
Returns delegated from Question#category.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/answer.rb', line 29 class Answer < ApplicationRecord belongs_to :ticket belongs_to :question has_one_attached :file delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true delegate :happening_id, to: :ticket, allow_nil: true, prefix: true delegate :attached?, to: :file, prefix: true validates :question, uniqueness: { scope: :ticket } validates :question_happening_id, comparison: { equal_to: :ticket_happening_id } validates :file, presence: true, if: :question_category_file? validates :value, absence: true, if: :question_category_file? validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file? validates :value, inclusion: { in: :options_title }, if: :question_category_select? # @return list of valid option for value def .acceptable.pluck :title end end |
#options ⇒ Array
Returns delegated from Question.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/answer.rb', line 29 class Answer < ApplicationRecord belongs_to :ticket belongs_to :question has_one_attached :file delegate :category, :category_file?, :category_select?, :happening_id, :options, :mandatory?, :title, to: :question, allow_nil: true, prefix: true delegate :happening_id, to: :ticket, allow_nil: true, prefix: true delegate :attached?, to: :file, prefix: true validates :question, uniqueness: { scope: :ticket } validates :question_happening_id, comparison: { equal_to: :ticket_happening_id } validates :file, presence: true, if: :question_category_file? validates :value, absence: true, if: :question_category_file? validates :value, presence: true, if: :question_mandatory?, unless: :question_category_file? validates :value, inclusion: { in: :options_title }, if: :question_category_select? # @return list of valid option for value def .acceptable.pluck :title end end |
#options_title ⇒ Object
Returns list of valid option for value.
46 47 48 |
# File 'app/models/answer.rb', line 46 def .acceptable.pluck :title end |