V1::UserSerializer end def jobs render json: user.jobs, each_serializer: V1::JobSerializer end def parent render json: user.parent, serializer: V1::UserSerializer end private def user @user ||= User.find(params[:user_id]) end end
user, serializer: V1::UserSerializer end end class V1::Users::JobsController < ApplicationController include V1::Users::ControllerConcern def index render json: user.jobs, each_serializer: V1::JobSerializer end end class V1::Users::ParentsController < ApplicationController include V1::Users::ControllerConcern def show render json: user.parent, serializer: V1::UserSerializer end end /v1/users/:user_id /v1/users/:user_id/jobs /v1/users/:user_id/parent
:user, :ranking delegate :id, to: :ranking delegate :name, to: :ranking delegate :ranking_users, to: :ranking def my_score ranking_users.find_by(user_id: user.id)&.score end end
UserRanking.new(ranking: ranking, user: user) render json: user_ranking, serializer: V1::UserRankingSerializer end private def ranking @ranking ||= Ranking.find(params[:id]) end def user @user ||= if params[:user_id] == 'me' current_user! else User.find(params[:user_id]) end end end
UserRanking.new(ranking: ranking, user: user) render json: user_ranking, serializer: V1::UserRankingSerializer end private def ranking @ranking ||= Ranking.find(params[:id]) end def user @user ||= if params[:user_id] == 'me' current_user! else User.find(params[:user_id]) end end end params ͔ΒऔΕΔσʔλ privateϝιουʹ·ͱΊΔ