Output JSON instead of HTML

suggest change
class UsersController < ApplicationController
  def index
    hashmap_or_array = [{ name: "foo", email: "foo@example.org" }]

    respond_to do |format|
      format.html { render html: "Hello World" }
      format.json { render json: hashmap_or_array }
    end
  end
end

In addition you will need the route:

resources :users, only: [:index]

This will respond in two different ways to requests on /users:

[
  {
    "name": "foo",
    "email": "foo@example.org"
  }
]

You can omit format.html { render inline: "Hello World" } if you want to make sure that your route will answer only to JSON requests.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


ActionController:
* Output JSON instead of HTML

Table Of Contents
3 Views
19 Caching
20 ActionController
23 Rails 5
25 Mongoid
26 Gems
55 CSV