3
2

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 3 years have passed since last update.

provideメソッド

Posted at

##Provideメソッドとは

日本語に訳すと
「供給する」「与える」

home.html.erb

<% provide(:title,"Home") %>
application.html.erb
<title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title>

application.html.erbは各viewで共通している部分のHTMLを書くファイルです。

provideメソッドで定義したものはlayoutファイル内においてyieldメソッドで呼び出すことができます。

こうすることで重複せずにビューを少ないコードで書くことができます(リファクタリング)

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?