1

我试图在设计中嵌套一个类,它将用户的技能和所需的技能保存到一个数组中,但我似乎无法让我的表单对象保存到数组中。

    Class User
 include Mongoid::Document
 devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

 ## Database authenticatable
 field :email,              :type => String, :null => false, :default => ""
 field :encrypted_password, :type => String, :null => false, :default => ""



 ## Recoverable
 field :reset_password_token,   :type => String
 field :reset_password_sent_at, :type => Time

 ## Rememberable
 field :remember_created_at, :type => Time

 ## Trackable
 field :sign_in_count,      :type => Integer, :default => 0
 field :current_sign_in_at, :type => Time
 field :last_sign_in_at,    :type => Time
 field :current_sign_in_ip, :type => String
 field :last_sign_in_ip,    :type => String


 field :first_name
 field :last_name

 field :location


 index([[:skills, :desired]], :background => true)

 validates_presence_of :first_name, :last_name,  :location
 validates_uniqueness_of :first_name, :last_name, :email, :case_sensitive => false
 attr_accessible :first_name, :last_name, :email, :password, :password_confirmation,     :remember_me,  :location

embeds_one :skills
end
 class Skills
 include Mongoid::Document

 field :skills, type => String
 field :desired, type => String

 embedded_in :user 
 end 

如何修复我的模型和视图,以便一个人可以在注册时添加多种技能和所需技能?(我是 Rails 初学者)

4

1 回答 1

1

embeds_oneembeds_many如果您想要一系列技能,应该是。

于 2012-04-19T15:36:55.160 回答