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

Fixed validation failing when using allow_nil => true options #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sankaranarayanan
Copy link

No description provided.

@cgriego
Copy link
Owner

cgriego commented Jun 16, 2013

@sankaranarayanan Can you share some example model code, how it behaves, and how you expect it to behave?

@sankaranarayanan
Copy link
Author

If you set to a empty string, it should return nil not 0. it should not type cast to to_i. That's why its failing in validations

check the example
In ActiveAttr::Model
user = User.new(:age => '')
=> User age: 0
user = User.new(:age => '')
=> User age: 0
user.age
=> 0

In ActiveRecord
user = User.new(:age => '')
=> UserInfo id: nil, age: nil, created_at: nil, updated_at: nil
user
=> User id: nil, age: nil, created_at: nil, updated_at: nil
user.age
=> nil

@cgriego
Copy link
Owner

cgriego commented Jun 18, 2013

Which validations? Please share some example model code.

@sankaranarayanan
Copy link
Author

class User
include ActiveAttr::Model
attribute :age, type: Integer

validates :age, :numericality => {:greater_than_or_equal_to => 0, :less_than_or_equal_to => 100}, :allow_nil => true
end

user = User.new(:age => '')
user.valid?
=> false
user.errors
=> ActiveModel::Errors:0xa8f3c5c @base=#<User age: 0>, @messages={:age=>["is not a number"]}

@cgriego
Copy link
Owner

cgriego commented Jun 19, 2013

Thank you for the details, @sankaranarayanan.

@AvnerCohen
Copy link

@cgriego is there any plan to merge this?

@joankaradimov
Copy link

+1

1 similar comment
@razitz
Copy link

razitz commented Aug 11, 2014

+1

@brynjargr
Copy link

@cgriego Will this ever get merged? As it stands, this issue is preventing me from being able to use this gem.

@andrewgilbert12
Copy link

+1

1 similar comment
@vladislav-zubov
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants