krunal shah
krunal shah

Reputation: 16339

Validation errors: how to get rid of "Validation failed: "?

whenever I do

        rescue Exception => e
        flash[:error] = e.message

the e.message will always contain the "Validation error:" string and the Object

Example:

Validation failed: Price "message:", Price "message"

How do I tell rails that I just want the message? and not the other parts of the validation error to be displayed?

Upvotes: 0

Views: 1720

Answers (1)

Steve Jorgensen
Steve Jorgensen

Reputation: 12391

You can get the data you want from the #errors attribute of the model you were trying to save. There could potentially be multiple validation errors (not just one).

See http://api.rubyonrails.org/classes/ActiveModel/Errors.html

Upvotes: 1

Related Questions