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 "Luke", akas: ["LSW", "Skywalker"]).attributes
=> {"name"=>"Luke", "akas"=>["LSW", "Skywalker"]}
See More #rails TILs
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.