-
Notifications
You must be signed in to change notification settings - Fork 325
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
NumericalityValidator support for activemodel #382
Comments
I think I'm running into this also when I try to use "validates_on_numericality_of":
If someone can give me a little direction, I'd be happy to help fix this as we need it to be working for our project ASAP. Thanks! |
Here's two options to fix it:
|
I actually fixed it in Her and I have a pull request pending approval. |
Can you add a link here with you pull request? |
Yeah, I should have included this before. My pull request is here: #383 |
hi @glappen first off, thanks for the contribution. i've been on the road for a bit so haven't had much time to review PRs. apologies for the slow reply after looking at your PR and @kritik suggestion, i fear that a solution of this nature might just paper over the root cause -- that Her::Model is not compliant with ActiveModel. would you want to take a stab at a solution using that approach? |
I would be willing to take a stab at it. Can you elaborate a bit more
|
@hubert - Following up as I haven't heard anything (maybe because I forgot to mention you in my response). Are you suggesting @kritik 1st of 2nd option? monkey patch number validation or implement ActiveRecord::AttributeSet? Can you explain how implementing ActiveRecord::AttributeSet solves the problem here? Thanks! |
hi @glappen. i understand your confusion. we def shouldn't be pulling in anything from ActiveRecord. when i looked at it earlier, i must've misread it as ActiveModel. my issue with the solution may be that i don't like the way the situation with record_attributed_in_place is handled in ActiveModel. let me look a bit more closely and i'll get back to you. |
In the commit rails/rails@f888fad it was introduced the method
record_attribute_changed_in_place?
toActiveModel::Validations::NumericalityValidator
which callsrecord.attribute_changed_in_place?
.The intention was that if this method was added by
ActiveRecord::AttributeMethods::Dirty
then it would be called.The problem is that
Her::Model
doesn't include that and doesn't implement that but it responds to that because it assumes on https://github.com/remiprev/her/blob/master/lib/her/model/attributes.rb#L74 thatattribute_changed_in_place
is a new attribute.Her version: 0.8.1
Active model version: 4.2.4
The text was updated successfully, but these errors were encountered: