0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ページごとに表示タイトルを変化させる方法

0
Posted at

目次

①結論
②provideメソッドとyeildの使い方

①結論

ヘルパーメソッドを使用し、各ビューファイルでprovideメソッドを使用し、application.html.erbに共通で持たせれるようにする

②provideメソッドとyeildの使い方

index.html.erb
  <% provide(:title, "ホーム") %>
application.html.erb
  <%= full_title(yield(:title)) %>
任意のhelper

  def full_title(page_name = "") 
    base_title = "AttendanceApp"
    if page_name.empty? 
      base_title 
    else 
      page_name + " | " + base_title 
    end
  end

この記述を行うことで、ページごとにprovideメソッドを使用し、タイトルに表示させたい文字を代入することで、ページごとにタイトルを変更することができる。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?