-
-
Save DouweM/6188115 to your computer and use it in GitHub Desktop.
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": { "first_name": "Abhishek", "login_info_attributes": { "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 :first_name, type: String | |
field :last_name, type: String | |
embeds_one :login_info | |
accepts_nested_attributes_for :login_info | |
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 | |
respond_to :json | |
def index | |
@users = User.all | |
respond_with(@users) | |
end | |
def create | |
@user = User.create(user_params) | |
respond_with(@user) | |
end | |
private | |
def user_params | |
params.require(:user).permit( | |
:first_name, | |
:last_name, | |
login_info_attributes: [ | |
:username, | |
:password | |
] | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment