Class: Api::UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Api::UsersController
- Includes:
- ActionController::Serialization, LoggedInControllerConcern
- Defined in:
- app/controllers/api/users_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creates a new user.
-
#search ⇒ Object
Returns the user with matching email.
-
#show ⇒ Object
Renders the current user as json.
Instance Method Details
#create ⇒ Object
Creates a new user
10 11 12 13 14 15 16 17 |
# File 'app/controllers/api/users_controller.rb', line 10 def create @user = User.new(params.permit(:name, :email, :password, :password_confirmation)) if @user.save render json: @user, status: :created else render json: @user.errors., status: 422 end end |
#search ⇒ Object
Returns the user with matching email
‘GET /api/users/search?email=xxx`
31 32 33 34 35 36 37 38 |
# File 'app/controllers/api/users_controller.rb', line 31 def search user = User.where("email = ? AND id != ?", params[:email], @user.id).first if user render json: user else render json: {}, status: :not_found end end |
#show ⇒ Object
Renders the current user as json
‘GET /api/user/:id`
23 24 25 |
# File 'app/controllers/api/users_controller.rb', line 23 def show render json: @user end |