Amber: wrong number of arguments for macro 'validate'

Created on 28 Jan 2018  路  5Comments  路  Source: amberframework/amber

Description

model User

  validate(:email, "is required", ->(user : self) {
    (email = user.email) ? !email.empty? : false
  })

this validation was created by generator

Steps to Reproduce

  1. amber w
$ ../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...

Versions

amber 0.6.4, Ubuntu 16.04, Crystal 0.24.1 (2017-12-22)

Most helpful comment

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

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elorest picture elorest  路  6Comments

bigforcegun picture bigforcegun  路  3Comments

faustinoaq picture faustinoaq  路  5Comments

conradwt picture conradwt  路  3Comments

Meldanor picture Meldanor  路  4Comments