Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. rapha@momo:~/Tippspiel/Trunk$ script/console
  2. Loading development environment.
  3. *** init.rb
  4. *** custom_error_message.rb
  5. >> ue = UserExtension.new
  6. => #<UserExtension:0xb7182114 @attributes={"team_id"=>nil, "forename"=>"", "t_false"=>nil, "former_place"=>0, "points"=>nil, "nick"=>"", "scorer_id"=>nil, "comp"=>"", "gender"=>"", "cust_no"=>"", "tend"=>nil, "t_true"=>nil, "departm"=>"", "position"=>"", "pos"=>nil, "surname"=>""}, @new_record=true>
  7. >> ue.save
  8. => false
  9. >> ue.errors.full_messages
  10. => ["Forename ^can't be blank", "Nick can't be blank", "Surname can't be blank"]
  11. >> module ActiveRecord
  12. >> class Errors
  13. >>
  14. ?> # Redefine the ActiveRecord::Errors::full_messages method:
  15. ?> # Returns all the full error messages in an array. 'Base' messages are handled as usual.
  16. ?> # Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
  17. ?> # in which case the attribute name is omitted.
  18. ?> # E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
  19. ?> def full_messages
  20. >> fm = []
  21. >>
  22. ?> @errors.each_key do |attr|
  23. ?> @errors[attr].each do |msg|
  24. ?> next if msg.nil?
  25. >>
  26. ?> if attr == "base"
  27. >> fm << msg
  28. >> elsif msg =~ /^\^/
  29. >> fm << msg[1..-1]
  30. >> else
  31. ?> fm << @base.class.human_attribute_name(attr) + " " + msg
  32. >> end
  33. >> end
  34. >> end
  35. >>
  36. ?> return fm
  37. >> end
  38. >> end
  39. >> end
  40. => nil
  41. >> ue.errors.full_messages
  42. => ["can't be blank", "Nick can't be blank", "Surname can't be blank"]
  43. >>
Add Comment
Please, Sign In to add comment