2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

なぜパーシャル(部分テンプレート)に切り出すの?

Posted at

パーシャルとは、共通パーツを切り出したテンプレート部分のこと。
Railsではrender "devise/shared/links"のように呼び出します。

✅ パーシャルのメリット

理由 内容
📦 DRY原則 同じリンクやパーツを再利用できる(Don’t Repeat Yourself)
🔧 保守性UP 1箇所修正するだけで、すべての画面に反映✨
🎨 UI統一 Bootstrap等のスタイルも一括調整しやすい
🚀 読みやすさ mainファイルがスッキリ!ロジックとUIの分離にもつながる

📝 使用方法例

= render "devise/shared/links"

📁 ファイルの作成例

touch app/views/devise/shared/_links.html.slim

📄 中身の例(I18n対応済み)

= link_to t("devise.shared.links.sign_in"), new_session_path(resource_name)
= " / "
= link_to t("devise.shared.links.sign_up"), new_registration_path(resource_name)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?