---
title: "Rails 5 Attributes from Active Record to Active Model"
description:
  "In Rails 5 we can use attribute assignment outside of Active Record inherited
  classes"
canonical_url: "https://www.bigbinary.com/blog/rails-5-moved-assign-attributes-from-activerecord-to-activemodel"
markdown_url: "https://www.bigbinary.com/blog/rails-5-moved-assign-attributes-from-activerecord-to-activemodel.md"
---

# Rails 5 Attributes from Active Record to Active Model

In Rails 5 we can use attribute assignment outside of Active Record inherited
classes

- Author: Mohit Natoo
- Published: May 17, 2016
- Categories: Rails 5, Rails

Before Rails 5, we could use `assign_attributes` and have bulk assignment of
attributes only for objects whose classes are inherited from
`ActiveRecord::Base` class.

In Rails 5 we can make use of `assign_attributes` method and have bulk
assignment of attributes even for objects whose classes are not inherited from
`ActiveRecord::Base`.

This is possible because the attributes assignment code
[is now moved](https://github.com/rails/rails/pull/10776) from
`ActiveRecord::AttributeAssignment` to `ActiveModel::AttributeAssignment`
module.

To have this up and running, we need to include
`ActiveModel::AttributeAssignment` module to our class.

```ruby

class User
  include ActiveModel::AttributeAssignment
  attr_accessor :email, :first_name, :last_name
end

user = User.new
user.assign_attributes({email:      'sam@example.com',
                        first_name: 'Sam',
                        last_name:  'Smith'})
> user.email
#=> "sam@example.com"
> user.first_name
#=> "Sam"

```

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-moved-assign-attributes-from-activerecord-to-activemodel)
