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 1 year has passed since last update.

【Rails】Provideメソッド

Last updated at Posted at 2022-02-18

使い方

:titleに'sample'定義

sample.html.erb
<% provide(:title, 'sample') %> 

yieldで:titleに定義した'sample'を受け取って描写
sample_application.html.erb
<title><%= yield(:title) %></title>


例)ボタンの文字の場合

:button_textに'Button'を定義

button.html.erb
<% provide(:button_text, 'Button') %>

f.submitでボタン作成、そのボタン上の文字にyield(:button_text)で受け取ったButtonを描写する
button_application.html.erb
<%= f.submit yield(:button_text), class: "btn" %>


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?