Which code would you add to return a 404 to the API caller if the user is not found in the database?
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
render json: @user, status: :ok,
# Missing code
end
A.
rescue => e
logger.info e
end
B.
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found_response
C.
rescue ActiveRecord::RecordNotFound
render json: { message: 'User not found' }, status: :not_found
end
D.
raise ActiveRecord::RecordNotFound
render json: { message: 'User not found' }, status: :user_not_found
end