我从如下符号添加了 getter 和 setter:
class User < ActiveRecord::Base
GENDER = { male: 2, female: 1}
def gender
GENDER.key(read_attribute(:gender))
end
def gender=(g)
write_attribute(:gender, GENDER[g.to_sym])
end
end
如何添加选择字段以选择性别?我想从GENDER
.
= simple_form_for [:member, @member] do |f|
= f.input :gender