---
title: "Rails 6.1 adds values_at attribute method for Active Record"
description: "Rails 6.1 adds values_at attribute method for Active Record"
canonical_url: "https://www.bigbinary.com/blog/rails-6-1-adds-values_at-attribute-method-for-active-record"
markdown_url: "https://www.bigbinary.com/blog/rails-6-1-adds-values_at-attribute-method-for-active-record.md"
---

# Rails 6.1 adds values_at attribute method for Active Record

Rails 6.1 adds values_at attribute method for Active Record

- Author: Chetan Gawai
- Published: November 17, 2020
- Categories: Rails 6.1, Rails

Rails 6.1 simplifies retrieving values of attributes on the Active Record model
instance by adding the `values_at` attribute method. This is similar to the
`values_at` method in `Hash` and `Array`.

Let's check out an example of extracting values from a `User` model instance.

```ruby

class User < ApplicationRecord
  def full_name
    "#{self.first_name} #{self.last_name}"
  end
end

 >> user = User.new(first_name: 'Era', last_name: 'Das' , email: 'era@gmail.com')

=> User id: nil, first_name: "Era", last_name: "Das", created_at: nil, updated_at: nil, email: "era@gmail.com", password_digest: nil

```

#### Before Rails 6.1

As shown below using `values_at` for `full_name`, which is a method, returns
`nil`.

```ruby
>> user.attributes.values_at("first_name", "full_name")
=> ["Era", nil]
```

#### After changes in Rails 6.1

Rails 6.1 added the `values_at` method on Active Record which returns an array
containing the values associated with the given methods.

```ruby
>> user.values_at("first_name", "full_name")
=> ["Era", "Era Das"]
```

Check out the [pull request](https://github.com/rails/rails/pull/36481) for more
details.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-1-adds-values_at-attribute-method-for-active-record)
