LoginSignup
1

More than 5 years have passed since last update.

Ruby on Rails基礎編 ルーティング

Posted at

引き続き 秀逸な教材progateの学習メモ

*ブラウザ>ルーティング>コントローラ(アクション)>ビュー>ブラウザ という動き

*Gatebookのaboutページ:localhost:3000/about

*Railsでは、アクションはファイル名を手掛かりにビューを探すので、ビューのフォルダ名とファイル名は非常に重要。ビューのフォルダ名=コントローラ名、ビュールファイル名=アクション名

*ルーティグファイル
Rails.application.routes.draw do
get '/about' => 'home#about'
end

*ブラウザ>localhost:3000 > ルーティング get 'top' => 'home#top' > homeコントローラ def top end > home/top.html.erb

*ターミナルで、rake routesをコマンド入力すると、ルーティングの一覧が表示され、URL(リクエスト)に対応するコントローラとアクションを確認できる。ルーティングを確認し、正しいURLを指定する。
$ rake routes
Prefix verb URI Pattern(URLのパターン) Controller#Action(URLに対応するアクション)
home_top / GET / home/top / home#top
about ? GET / /about / home#about

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1