Rails チュートリアル 1章 勉強メモ17

Rails チュートリアルの勉強メモ

railstutorial.jp

  • 前回までのあらすじ
  • hello メソッドにたどり着くまでをみた
  • インターネットにデタラメを残している気がする間違えてるところあったら直します

演習

    1. helloアクションを書き換え、「hello, world!」の代わりに「hola, mundo!」と表示されるようにしてみましょう。
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  def hello
    render html: "hola, mundo!"
  end
end
  • 2.「非ASCII文字」もサポートされているので。「¡Hola, mundo!」を表示しましょう(意訳
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  def hello
    render html: "¡Hola, mundo!"
  end
end
  • 表示できた

  • 3.helloアクションを参考にして、2つ目のアクションgoodbyeを追加しましょう。このアクションは、「goodbye, world!」というテキストを表示します。ルーティングを編集して、ルートルーティングの割り当て先をhelloアクションからgoodbyeアクションに変更します

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  def hello
    render html: "¡Hola, mundo!"
  end

  def goodbye
    render html: "goodbye, world!"
  end
end
Rails.application.routes.draw do
  root 'application#goodbye'
end
  • 表示された

git

  • 直接関係ないのでスルーで(一応目は通しました

デプロイする