Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:57:56+00:00 2026-06-01T11:57:56+00:00

I’m relatively new to Ruby, Sinatra, and DataMapper, but have a question about DataMapper

  • 0

I’m relatively new to Ruby, Sinatra, and DataMapper, but have a question about DataMapper validation errors.

I know you can see any errors that occur when attempting to save a new row to the database with DataMapper by doing something like the following:

user = User.new username: 'bradleygriffith', password: 'not_my_password'
if user.save
  #success!
else
  user.errors.each do |error|
    puts error
  end
end

What I would like to be able to do is determine on which property the error occurred. This way, for example, I might be able to place error messages next to the appropriate fields in my registration form. That is, I want to know that the registrant entered, say, an invalid username before displaying the error message so that I could place the message along-side the username field.

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:57:57+00:00Added an answer on June 1, 2026 at 11:57 am

    The errors object is an instance of DataMapper::Validations::ValidationErrors which has an on method that will return an array containing all the validation error messages for the property you pass as a parameter, or nil if there are no errors. (It looks like those docs don’t actually match the implementation).

    user = User.new username: 'joe', :age => 40
    
    if user.save
      #success!
    else
      puts "Username: #{user.username} #{user.errors.on(:username)}"
      puts "Age: #{user.age} #{user.errors.on(:age)}"
    end
    

    produces (with suitable validations set up):

    Username: joe ["Username must be between 4 and 20 characters long"]
    Age: 40 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to ruby on rails, so this question might be easy.
I am relatively new to Ruby, but I am trying to catch a variable
I'm relatively new to Ruby and have limited time therefore I try out simple
I'm relatively new to Ruby on Rails. As of now have this working code
Being relatively new to the .net game, I was wondering, has anyone had any
I'm relatively new to J2ME and about to begin my first serious project. My
I'm relatively new to web application programming so I hope this question isn't too
I'm relatively new to Nant, what i'd like to do is have a task
I am still relatively new to unit testing. I have written a class in
Okay, so I am new to Ruby and I have a strong background in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.