Skip to content

Instantly share code, notes, and snippets.

@abhishek0
Created August 8, 2013 19:33
Show Gist options
  • Save abhishek0/6187901 to your computer and use it in GitHub Desktop.
Save abhishek0/6187901 to your computer and use it in GitHub Desktop.
Simple mongoid models and creation controllers
curl http://localhost:3000/users -d "{'user': {'firstName': 'Abhishek', 'loginInfo':{'password':'p'}}}"
class User
include Mongoid::Document
store_in collection: "dummy"
field :firstName, type: String
field :lastName, type: String
embeds_one :logininfo, store_as: "loginInfo"
end
class Logininfo
include Mongoid::Document
field :username, type: String
field :password, type: String
embedded_in :user
end
class UsersController < ApplicationController
def index
render :json => User.all
end
def create
User.create(params[:user]).save!
render :json => "ok"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment