I have a Address model that contains the following validation:
with_options if: Proc.new{|i| i.country && i.country.downcase == "united states"} do
validates :state, presence: true
end
In my new and edit form, I want to check and see if the state field is required. The following function returns the presence validation but it does not take my conditional into consideration.
Address.new._validators[:first_name]
This code returns
[#<ActiveRecord::Validations::PresenceValidator:0x00007fadebc9d8a8 @attributes=[:first_name], @options={:if=>#<Proc:0x00007fadebc9ebb8@/Users/cannonmoyer/Documents/RailsProjects/treadmilldoctorrails/app/models/address.rb:18>}>]
Is there a way to run the conditional for the validation so that the presence validator doesn't appear on each instance? I am wanting to use this to set required fields within my HTML.