Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation doesn't work if the value is represented as a string #91

Open
krtschmr opened this issue Aug 4, 2022 · 0 comments
Open

Validation doesn't work if the value is represented as a string #91

krtschmr opened this issue Aug 4, 2022 · 0 comments

Comments

@krtschmr
Copy link

krtschmr commented Aug 4, 2022

We have an object that can hold a value which is just a string. Depends on the STI Child of the object, a specific validation is running.

t.string :value, null: true

class SmartField < ApplicationRecord
  validates :value, date: true
end


SmartField.create! value: Date.today
ActiveRecord::RecordInvalid: Validatie mislukt: Value is geen datum

this looks very odd to me and was unexpected.

      def is_time?(object)
        object.is_a?(Time) || (defined?(Date) and object.is_a?(Date)) || (defined?(ActiveSupport::TimeWithZone) and object.is_a?(ActiveSupport::TimeWithZone))
      end

do we need a string check, aka Date.parse rescue false?

@krtschmr krtschmr changed the title Not working as expected, what am i missing? Validation doesn't work if the value is represented as a string Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant