Create Action
add actionsetting / routing
/app/controllers/hello_controller.rb
class HelloController < ApplicationController
def index
render plain:"Hello, This 1s Rails sample page!"
end
end
routes.rb
Rails.application.routes.draw do
get "hello/index"
get "hello", to: 'hello#index'
end
http://127.0.0.1:3000/hello <- hello/index 省略可
解説
get
"アドレス", to: 'コントローラー#アクション'
to:=
自動的に割り当てるコントローラーやメソッドではなく、実行するアクションメソッドを自分で明示的に指定したい時に設定する。http://localhost:3000/hello
にアクセスしたら、to: 'hello#index'
を呼び出す=
HelloController
クラスのindex
メソッドを呼び出す
最終更新
役に立ちましたか?