Skip to content

Instantly share code, notes, and snippets.

@DouweM
Forked from abhishek0/request
Last active December 20, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DouweM/6188115 to your computer and use it in GitHub Desktop.
Save DouweM/6188115 to your computer and use it in GitHub Desktop.
curl http://localhost:3000/users -d '{"user": { "first_name": "Abhishek", "login_info_attributes": { "password": "p"}}}'
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
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