Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Rails 5.2
- class User < ApplicationRecord
- validates :email, presence: true
- end
- > user = User.new
- => #<User id: nil, name: nil, email: nil, rating: 0, password: nil, created_at: nil, updated_at: nil>
- > user.valid?
- => false
- > user.errors
- => #<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}]}>
- > user.errors.slice!
- => Traceback (most recent call last):
- 1: from (irb):16
- NoMethodError (undefined method 'slice!' for #<ActiveModel::Errors:0x00007fa1f0e46eb8>)
- Did you mean? slice_when
- > errors = user.errors.to_h
- > errors.slice!(:email)
- => {:password=>["can't be blank"]}
- > errors
- => {:email=>["can't be blank"]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement