Last active
October 6, 2016 11:34
-
-
Save marostr/3b58e8bb7b803b4b1f5dd299e2687c6f to your computer and use it in GitHub Desktop.
users_controller.rb
This file contains hidden or 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 | |
| before_action :set_user, only: [:show, :edit, :update, :destroy] | |
| def index | |
| @users = Users.all | |
| render json: @users, each_serializer: UserSerializer | |
| end | |
| def show | |
| render json: @user, serializer: UserSerializer | |
| end | |
| def create | |
| creator = UserCreator.new(user_params, current_user) | |
| if creator.call | |
| head :ok | |
| else | |
| render json: { errors: creator.errors.messages }, status: :unprocessable_entity | |
| end | |
| end | |
| def update | |
| @user.assign_attributes(user_params) | |
| if @user.save | |
| render json: @user, serializer: UserSerializer | |
| else | |
| render json: { errors: @user.errors.messages }, status: :unprocessable_entity | |
| end | |
| end | |
| private | |
| def set_user | |
| @user = User.find(params[:id]) | |
| end | |
| def user_params | |
| params.require(:user).permit(:show_dmca, :name, :user_group_id, :email) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment