model User
validate(:email, "is required", ->(user : self) {
(email = user.email) ? !email.empty? : false
})
this validation was created by generator
$ ../amber-stable/bin/amber w
07:11:44 Watcher | (INFO) Watching 18 files (server reload)...
07:11:44 Watcher | (INFO) Building project Work_tracker...
Error in src/work_tracker.cr:1: while requiring "../config/*"
require "../config/*"
^
in config/application.cr:3: while requiring "../src/models/**"
require "../src/models/**"
^
in src/models/user.cr:12: wrong number of arguments for macro 'validate' (given 3, expected 1, 2)
validate(:email, "is required", ->(user : self) {
^~~~~~~~
07:11:45 Watcher | (INFO) Compile time errors detected. Shutting down...
amber 0.6.4, Ubuntu 16.04, Crystal 0.24.1 (2017-12-22)
this validation was created by generator
@olegsobchuk Thank you for reporting this issue! This was a breaking change introduced by Granite::ORM on https://github.com/amberframework/granite-orm/pull/117
Fixed by #588
Meanwhile try this:
validate :email, "is required" do
return true unless email.to_s.blank?
false
end
@faustinoaq Hay, guess
validate :email, "is required" do
!email.to_s.empty?
end
a little bit more elegant. As I understood there is a problem with nil value?
but I didn't understand why
email.nil? ? false : !email.empty?
doesn't work?
I've got same issue
repo here :) only amber g auth User
https://github.com/ChangJoo-Park/for-issue-granite-orm-validator
password validation here :)
thanks @faustinoaq
validate :password, "is too short" do
return password_changed? ? valid_password_size? : true
false
end
Yeah, @ChangJoo-Park also check this 馃憠 https://github.com/amberframework/granite-orm/pull/131
Most helpful comment
@olegsobchuk Thank you for reporting this issue! This was a breaking change introduced by Granite::ORM on https://github.com/amberframework/granite-orm/pull/117
Fixed by #588
Meanwhile try this: