Search⌘ K
AI Features

Show Users

Understand how to define and test the show action in a Rails API user controller. Explore adding routes, verifying JSON responses, and handling HTTP status codes to ensure user data is correctly accessible through API endpoints.

Define the show action

We will define the show action by simply adding the action to our controllers in app/controllers/api/v1/users_controller.rb. The code for the show function is as follows:

Ruby
class Api::V1::UsersController < ApplicationController
# GET /users/1
def show
render json: User.find(params[:id])
end
end

Add test

There are two things we want to test for an API:

...