Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

typo in validation block example? #111

@wgreene

Description

@wgreene

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions