I am a junior developer (Ruby on Rails 5) currently implementing a new validation on an existing model. The validation only passes if the attribute in question is no greater than 50 words.
validates_length_of :reason, maximum: 50, too_long: 'Please reduce to 50 words or less',
tokenizer: ->(str) { str.split(/\s+/) }
Unfortunately there are already 54 records in our database which violate this validation. So, I'm searching for a solution to ensure the validation would never get run for these pre-existing records.
My research so far has yielded the on: :create option which seems promising, but I wanted some experienced feedback on whether I might run into problems/bugs down the line.
Will this validation option give me exactly the behaviour I want?
Thanks folks!