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

typo in validation block example? #111

Open
wgreene opened this issue Dec 11, 2015 · 1 comment
Open

typo in validation block example? #111

wgreene opened this issue Dec 11, 2015 · 1 comment

Comments

@wgreene
Copy link

wgreene commented Dec 11, 2015

Apologies in advance if I am making a mistake, but I was having some trouble following the validation block example from the repo readme. I think perhaps the example has a minor typo?

validates :first_name do |object, name, value|
  object.errors[name] << "must be over 4 chars long" if value.length <= 4

After digging into the library code a bit I was able to get things working by accessing the @errors hash as object._errors. For example, in my code:

validates :domain do |object, name, value|
  regex = /^www\.[a-z]+\.com$/
  message = 'domain must be formatted like www.domain.com'
  object._errors[name] << message unless value =~ regex
end

The hash returned by the object.errors accessor was not initialized properly if a validation block was the first error reached but seemed to work fine if there was another validation clause failing.

Also want to say - Really happy I found this gem. Has been working great for what I'm trying to do using an existing python flask-restless API as a data service for my Rails front end. ActiveResource was not easy to get working and other gems didn't have the nice ActiveRecord-like features. Thanks so much!

@andyjeffries
Copy link
Contributor

Fixed in the Flexirest fork - flexirest/flexirest@9f14a3f

Thanks for your kind words.

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

No branches or pull requests

2 participants