控制器(基本)

class UsersController < ApplicationController
  def index
    respond_to do |format|
      format.html { render html: "Hello World" }
    end
  end
end

這是一個基本控制器,新增了以下路由(在 routes.rb 中):

resources :users, only: [:index]

當你訪問 URL /users 時,將在網頁中顯示 Hello World 訊息