I have two model association as follows: Survey_question and survey_answer.
Survey_question Model
class SurveyAnswer < ApplicationRecord
belongs_to :survey_question
validates_presence_of :answer_content, if: "answer_type!=Radio Button"
end
Survey_question Model
class SurveyQuestion < ApplicationRecord
belongs_to :user
belongs_to :survey
has_many :survey_answers
accepts_nested_attributes_for :survey_answers, allow_destroy: true
has_many :survey_responses
accepts_nested_attributes_for :survey_responses
validates :question_content, presence: true
validates :answer_type, presence: true
end
I just to validate presence of survey_answer's answer_content when survey_question's answer_type is "Radio Button" ? how can I achieve this ?? thanks in advance.