public Method

Errors.add(attribute, msg)

Adds an error to an Active Resource object’s attribute (named for the attribute parameter) with the error message in msg.

Examples

my_resource = Node.find(1)
my_resource.errors.add('name', 'can not be "base"') if my_resource.name == 'base'
my_resource.errors.on('name')
# => 'can not be "base"!'

my_resource.errors.add('desc', 'can not be blank') if my_resource.desc == ''
my_resource.valid?
# => false
my_resource.errors.on('desc')
# => 'can not be blank!'

Source Code

# File active_resource/validations.rb, line 50
def add(attribute, msg)
  @errors[attribute.to_s] = [] if @errors[attribute.to_s].nil?
  @errors[attribute.to_s] << msg
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.