🔺
Rails
  • Rails Wiki
  • Ruby
    • Ruby Basic Loop
    • Ruby Basic Method
    • Fizz Buzz on Rails
  • Rails Note
    • DBの形式変換Rais6
    • Rails開発環境
      • Rails on Docker 導入フロー
    • 2022 Re:Rails
    • Hello Rails
      • Genarate Controllr
      • Create Action
  • Zero One [QA Service]
    • QA-Servrice Index
    • Setting
    • Crate Model Base
    • Add Bootstrap/FontAwesome
    • Save Model on Save
  • Rails Vue
    • Add Vue on Rails
GitBook提供
このページ内

役に立ちましたか?

  1. Rails Note
  2. Hello Rails

Create Action

add actionsetting / routing

前へGenarate Controllr次へQA-Servrice Index

最終更新 2 年前

役に立ちましたか?

/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

解説

  • get "アドレス", to: 'コントローラー#アクション'

  • to:=自動的に割り当てるコントローラーやメソッドではなく、実行するアクションメソッドを自分で明示的に指定したい時に設定する。

  • http://localhost:3000/hello にアクセスしたら、to: 'hello#index'を呼び出す

  • = HelloController クラスのindexメソッドを呼び出す

<- hello/index 省略可

http://127.0.0.1:3000/hello
http://127.0.0.1:3000/hello/index127.0.0.1
http://127.0.0.1:3000/hello
set Controller & Routeing · BoxPistols/dev-rails6-211031@5f2d1cdGitHub
set Controller & Routeing
Logo