Advertisement
Guest User

Untitled

a guest
May 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # Rails 5.2
  2. class User < ApplicationRecord
  3. validates :email, 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:0x00007fc46700df10 @base=#<User id: nil, name: nil, email: nil, rating: 0, password: nil, created_at: nil, updated_at: nil>, @messages={:email=>["can't be blank"], :password=>["can't be blank"]}, @details={:email=>[{:error=>:blank}], :password=>[{:error=>:blank}]}>
  14.  
  15. > user.errors.slice!
  16. => Traceback (most recent call last):
  17. 1: from (irb):16
  18. NoMethodError (undefined method 'slice!' for #<ActiveModel::Errors:0x00007fa1f0e46eb8>)
  19. Did you mean? slice_when
  20.  
  21. > errors = user.errors.to_h
  22.  
  23. > errors.slice!(:email)
  24. => {:password=>["can't be blank"]}
  25.  
  26. > errors
  27. => {:email=>["can't be blank"]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement