0

我从如下符号添加了 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
4

1 回答 1

2

您需要使用集合,请参阅此处的文档:https ://github.com/plataformatec/simple_form#collections

 <%= f.input :gender, collection: User::GENDER.keys %>
于 2013-11-01T11:03:19.517 回答