Today I Learned

hashrocket A Hashrocket project

Use an array with Rails' attribute API

Attributes can be arrays by removing the type and adding array: true:

class User
  include ActiveModel::Model
  include ActiveModel::Attributes

  attribute :name, :string, default: "n/a"
  attribute :akas, array: true, default: []
end

User.new(name: "Luke", akas: ["LSW", "Skywalker"]).attributes
=> {"name"=>"Luke", "akas"=>["LSW", "Skywalker"]}
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.