ruby - Pass parameter to Validation - Rails 3 -
we valid different sections via following code:
on_boarding_form.rb
def valid? @sections.all? {|section| section.valid?} end this goes on_boarding_section_form.rb. checks
validate @fields.where(:required => true).where(:hidden => false).each |req_field| if req_field.name.to_s == 'favor' binding.remote_pry end if defined? land1 if land1 == 'be' && req_field.name.to_s == 'ort01' # nothing elsif land1 == 'be' && req_field.name.to_s == 'entk2' # nothing elsif land1 == 'be' && req_field.name.to_s == 'pstlz' #validate postal code @errors.add_on_blank(req_field.name.downcase.to_sym) elsif land1 != 'be' && req_field.name.to_s == 'ort01' @errors.add_on_blank(req_field.name.downcase.to_sym) elsif land1 != 'be' && req_field.name.to_s == 'entk2' @errors.add_on_blank(req_field.name.downcase.to_sym) elsif land1 != 'be' && req_field.name.to_s == 'pstlz' # nothing else @errors.add_on_blank(req_field.name.downcase.to_sym) end else @errors.add_on_blank(req_field.name.downcase.to_sym) end end @fields.where(:hidden => false).each |field| next if field.field_type =~ /g/i next if field.field_type =~ /d/i next if field.field_type =~ /p/i validates_with lengthvalidator, :attributes => field.name.downcase.to_sym, :in => 0..field.field_length end end in sections emergency contact need check if person married or not. if person married emergency contact fields should required.
now question in on_boarding_form.rb possible pass parameter on_boarding_section_form.rb can pass marital status.
thank you!
kind regards, vincent
Comments
Post a Comment