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