class Api::V1::UsersController < Api::V1::ApplicationController skip_before_action :authenticate_user_from_token, only: [:show] before_action :fetch_current_user, only: [:show] before_action :load_user, except: [:me, :search] def show render json: @user, serializer: UserSerializer end def me render json: @current_user end def search users = User.where('name LIKE ?', "%#{params[:keywords]}%").page(params[:page]) render json: users, each_serializer: UserSerializer end private def load_user @user = User.find_by id: params[:id] render json: {msg: '不能找到该用户'}, status: 404 unless @user end end