Class: Api::V1::UsersController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V1::UsersController
- Defined in:
- lib/generators/jwt_api/templates/api/v1/users_controller.rb
Overview
User controller
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#me ⇒ Object
‘/api/v1/me’.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 7 def create unless user_params[:password] == user_params[:password_confirmation] return render json: { message: "passwords don't match" }, status: :unprocessable_entity end user = User.new(user_params) user.jti = SecureRandom.uuid if user.save render partial: 'users/user', locals: { user: user }, status: :created else render json: user.errors, status: :unprocessable_entity end end |
#destroy ⇒ Object
31 32 33 34 |
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 31 def destroy @current_user.destroy head :no_content end |
#me ⇒ Object
‘/api/v1/me’
22 23 24 |
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 22 def me render partial: 'users/user', locals: { user: @current_user } end |
#update ⇒ Object
26 27 28 29 |
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 26 def update @current_user.update(user_params.except(:password_confirmation, :reset_password_token)) render partial: 'users/user', locals: { user: @current_user } end |