Tuesday, 11 July 2006
Rails: Printing validation errors as flash notices (ruby)
I am quite sure someone has already found this simple solution, but when I poked around, I couldn't find it.
Here is my snippet to print out the error messages resulting from a validation as a flash notice:
if @user.save
flash[:'notice'] = "New user saved successfully."
elsif !@user.errors.empty?
flash[:'notice'] = "Could not save new user: "
<< @user.errors.full_messages.join("; ")
end
erin posted this on 11 July 2006, 06:43 PM · updated 18 December 2006, 04:40 PM
