Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Rails 6
- class User < ApplicationRecord
- validates :name, 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: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}]}>
- > user.errors.of_kind?(:name)
- => false
- > user.errors.of_kind?(:name, :blank)
- => true
- > user.errors.of_kind?(:name, "can't be blank")
- => true
- > user.errors.of_kind?(:name, "is blank")
- => false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement