Thursday, April 19, 2012

Rails, Mongoid, and Devise nested Models

I am trying to Nest a class within Devise that will hold a user's skills and desired skills into an array but I can not seem to get my form objects to save into the array.

    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
class Skills
include Mongoid::Document

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

embedded_in :user

How do I fix my model and view so a person can add multiple skills and desired skills as sign up? (I am a rails beginner)

No comments:

Post a Comment