LoginSignup
28
18

More than 3 years have passed since last update.

layoutメソッドについてまとめる!

Last updated at Posted at 2019-06-19

layoutメソッドとは???

コントローラによってヘッダーやフッターのデザインを変更したり、読み込むCSSを切り替えるメソッド!

実際のコードを見ながら、具体的に解説していきます!

layoutメソッドを使用する場合としない場合を比較する!

tweets.controller.rb
class TweetsController < ApplicationController
  layout 'hogehoge'

  def index
    @tweets = Tweet.includes(:user)
  end
end
○上記のコードの場合

tweetsコントローラのアクションが呼び出された際の、レイアウトファイルとしてapp/views/layouts/hogehoge.htmlが使われるようになる!

○上記のコードからlayout 'hogehoge'を抜いた場合

tweetsコントローラのアクションが呼び出された際の、レイアウトファイルとしてapp/views/layouts/application.htmlが読み込まれる!


とてもシンプルで、使い勝手も良さそうです!

何か質問等ございましたら、コメントお気軽にしてください!

ご静聴ありがとうございました!:relaxed:

28
18
0

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
28
18