Skip to content

Instantly share code, notes, and snippets.

@GiancarlosIO
Last active July 28, 2016 03:56
Show Gist options
  • Save GiancarlosIO/23cd4de484c9569fbd5e4cb4f878766e to your computer and use it in GitHub Desktop.
Save GiancarlosIO/23cd4de484c9569fbd5e4cb4f878766e to your computer and use it in GitHub Desktop.
# POST api/v1/users, params: { user: {email: '[email protected]', name: 'Giancarlos Isasi' } }
def create
if params[:user]
@user = User.with_token(params[:user]) # le pasamos la información que nuestro metodo 'with_token' usara para crear al usuario
@token = @user.tokens.create() # Al usuario que nos devuelve nuestro parametro 'with_token' le creamos un nuevo token
render "api/v1/users/show" # en esta vista mostraremos la info del usuario y su token respectivo
else
render json: { error: 'user params info is missing' } # solo si no nos envian la info necesaria
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment