ruby on rails - Listing user gender options in a view -
i seeking populate select list in form options user gender. have learning rails book uses similar approach credit card options creating array in model , referencing in view. unfortunayely when use approach receive error referencing line in view stating: "uninitialized constant gender_options"
class user < activerecord::base # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable gender_options = { "male" => :true, "female" => :false, "unspecified" => :nil} has_many :discussions has_many :comments end <div> <%= f.label :gender %><br /> <%= f.select :gender, user::gender_options %> </div>
try using helper , locale.
# app/helpers/application_helper.rb def gender_lists i18n.t(:gender_lists).map { |key, value| [ value, key ] } end # config/locale/en.yml en: gender_lists: "": unspecified "true": male "false": female
and on view, can this
<div> <%= f.label :gender %><br /> <%= f.select :gender, gender_lists %> </div>
===
note :
just suggestion, user string
type data instead of boolean
Comments
Post a Comment