Advertisement
Guest User

Untitled

a guest
May 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # Rails 6
  2. class User < ApplicationRecord
  3. validates :name, presence: true
  4. end
  5.  
  6. > user = User.new
  7. => #<User id: nil, name: nil, email: nil, rating: 0, password: nil, created_at: nil, updated_at: nil>
  8.  
  9. > user.valid?
  10. => false
  11.  
  12. > user.errors
  13. => #<ActiveModel::Errors:0x00007fc462a1d140 @base=#<User id: nil, name: nil, email: nil, rating: 0, password: nil, created_at: nil, updated_at: nil>, @messages={:name=>["can't be blank"]}, @details={:name=>[{:error=>:blank}]}>
  14.  
  15. > user.errors.of_kind?(:name)
  16. => false
  17.  
  18. > user.errors.of_kind?(:name, :blank)
  19. => true
  20.  
  21. > user.errors.of_kind?(:name, "can't be blank")
  22. => true
  23.  
  24. > user.errors.of_kind?(:name, "is blank")
  25. => false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement