Ruby on Rails Get Query Filter

Okechukwu Uneze
1 min readJun 10, 2022

--

Given a GET request is made to “/users?<some-query-here>”, then all users that meet the query criteria are returned in a JSON array, and the status code is 200.

first we will create our index action that renders users and set a before_action that calls filter_users before the index action is called.

class UsersController < ApplicationController
before_action :filter_users, only: %i[ index ]
# GET /users
def index
render json: @users, status: :ok
end
end

--

--