Rails mongoid

I have a strange problem. Suppose I have a user model with only name
I can add a field with value by creating an instance in mongodb rails


class User
include Mongoid::Document

field :name

Now in rails console, If you do
user = User.new
user[:name] = “xxxx”
user[:firstname] = “yyyy”

The record gets created with name and firstname fields. But i havent
declared firstname field in model.

Can anyone please help me out.


On 4 May 2011 09:18, Aashish K. [email protected] wrote:


Your keyboard is working fine. You may not see your original posting
sent back to you, depending on how your mailer and the list are setup.


On May 4, 9:18am, Aashish K. [email protected] wrote:

field :name

Can anyone please help me out.

Mongodb records don’t have a fixed schema - each document can store
arbitrary data. field :name just creates some convenient accessors for
you (and allows you to do things like say that a certain field is
required etc). See http://mongoid.org/docs/documents/dynamic.html


Thanks a lot Fred.

Can I know yr twitter id

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs