Created
August 8, 2013 19:33
-
-
Save abhishek0/6187901 to your computer and use it in GitHub Desktop.
Simple mongoid models and creation controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl http://localhost:3000/users -d "{'user': {'firstName': 'Abhishek', 'loginInfo':{'password':'p'}}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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