rmm5t / strip_attributes

:hocho: An ActiveModel extension that automatically strips all attributes of leading and trailing whitespace before validation. If the attribute is blank, it strips the value to nil.
https://github.com/rmm5t/strip_attributes
MIT License
558 stars 54 forks source link

Consider using the Rails 7.1 normalizes API instead of before_validation callbacks #67

Open rmm5t opened 11 months ago

rmm5t commented 11 months ago

Similar idea as #43

Investigate and perhaps consider using the new normalizes API in Rails 7.1 instead of a before_validation callback.

This would result in a major version bump for strip_attributes, but I would still like to attempt to maintain both forwards and backwards compatibility, to some extent possible.

tmaier commented 7 months ago

Great idea, however, normalizes only works for ActiveRecord. I think this is a major blocker, unless you want to have two different versions to maintain. One for ActiveRecord and one for ActiveModel etc.

I opened a "feature request" in the ruby on rails forum. Maybe you want to support this (with a "hear" and/or a comment) https://discuss.rubyonrails.org/t/proposal-activemodel-normalization/85405

tmaier commented 7 months ago

There would be some benefits: The normalizes API overrides the setter - in addition to a before_validation. And it applies also for where clauses.