Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- render json: {'user': {name: 'Peter' }}
- def index
- render json: @users, serializer: UserSerializer, adapter: :json_api
- end
- class UsersController < ApplicationController
- before_action :set_user, only: [:show, :update, :destroy]
- ...
- ...
- # GET /users/1
- def show
- render json: @user
- end
- ...
- ...
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_user
- @user = User.find(params[:id])
- end
- def user_params
- ActiveModelSerializers::Deserialization.jsonapi_parse(params)
- end
- end
- class UserSerializer < ActiveModel::Serializer
- attributes :id, :name, :email, :outro_atributo
- belongs_to :alguma_associação
- has_many :outra_associação
- has_one :alguma_outra_associação
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement