---
title: "Rails 6 adds ActiveModel::Errors#of_kind?"
description: "Rails 6 adds ActiveModel::Errors#of_kind?"
canonical_url: "https://www.bigbinary.com/blog/rails-6-adds-activemodel-errors-of_kind-"
markdown_url: "https://www.bigbinary.com/blog/rails-6-adds-activemodel-errors-of_kind-.md"
---

# Rails 6 adds ActiveModel::Errors#of_kind?

Rails 6 adds ActiveModel::Errors#of_kind?

- Author: Amit Choudhary
- Published: April 1, 2019
- Categories: Rails 6, Rails

Rails 6 added [of_kind?](https://github.com/rails/rails/pull/34866) on
`ActiveModel::Errors`. It returns true if the `ActiveModel::Errors` object has
provided a key and message associated with it. The default message is
`:invalid`.

[of_kind?](https://github.com/rails/rails/pull/34866) is same as
[ActiveModel::Errors#added?](https://api.rubyonrails.org/classes/ActiveModel/Errors.html#method-i-added-3F)
but, it doesn't take extra options as a parameter.

Let's checkout how it works.

#### Rails 6.0.0.beta2

```ruby
>> class User < ApplicationRecord
>>   validates :name, presence: true
>> end

>> user = User.new

=> => #<User id: nil, name: nil, password: nil, created_at: nil, updated_at: nil>

>> user.valid?

=> false

>> user.errors

=> #<ActiveModel::Errors:0x00007fc462a1d140 @base=#<User id: nil, name: nil, 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
```

Here is the relevant [pull request](https://github.com/rails/rails/pull/34866).

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-adds-activemodel-errors-of_kind-)
