ยง2023-03-04
1.2.4 Hello, world!
Controller actions are defined inside controllers. At this point the Application controller is the only controller we have, which you can verify by running
(FRUM) [alexlai@n2MnJaro hello_app]$ ls app/controllers/*_controller.rb
app/controllers/application_controller.rb
- original ~/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
end
- changed to
class ApplicationController < ActionController::Base
def hello
render html: "hello, world!"
end
end
- original config/routes.rb,
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
# root "articles#index"
end
- Chnaged to
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
# root "articles#index"
root "application#hello"
end