2012-04-19 5 views
1

私はDevise内でユーザーのスキルと望ましいスキルを配列に保持するクラスをネストしようとしていますが、フォームオブジェクトを配列に保存できないようです。サインアップするようRails、Mongoid、Devizesネストされたモデル

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 

は、私は私のモデルとビューを修正するにはどうすればよいので、人は複数のスキルや希望スキルを追加することができますか? (私はレールの初心者です)

+1

これは私の意見ですが、私はUserモデルを残して認証のみを扱い、別のリンクされた 'Profile'や' Person'モデルを持ってスキルを保持することをお勧めします。かなり素早くうずくまった。 – Russell

+0

私はまた、その権利を達成するためにdeviseモデルをオーバーライドする必要がありますか? – user1344267

+0

あなたがする必要があるのは、あなたの人物モデルに 'has_one:person'を、人物モデルに' belongs_to:user'を追加することです。逆もまた同様です。 – Russell

答えて

1

embeds_oneは、スキルが必要な場合はembeds_manyにする必要があります。

関連する問題