Make dynamic ActiveRecord attribute columns.
gem 'dynamic_attrs'
$ rails g dynamic_attrs
$ rake db:migrate
class User
include DynamicAttr::Owner
# Supporting 4 data types
# :string, :datetime, :boolean, :integer
has_dynamic_attrs :student_attrs,
:fields => {
:sid => :string,
:birthday => :datetime,
:is_graduated => :boolean,
:age => :integer
}
has_dynamic_attrs :teacher_attrs,
:fields => {
:tid => :string,
:birthday => :datetime,
:age => :integer
}
end
@user.teacher_attrs_tid = '0001'
@user.teacher_attrs_tid
# => '0001'
@user.student_attrs_is_graduated? = true
@user.student_attrs_is_graduated = true
@user.student_attrs_is_graduated?
@user.student_attrs_is_graduated
# => true
User.where_student_attrs(:is_graduated, true)
# => ActiveRecord::Relation [...]
User.where_teacher_attrs(:age, 35)
# => ActiveRecord::Relation [...]