初心者!current_userの使い方 〜ログイン中のユーザ名を表示〜
current_userでログイン中のユーザ名とメールアドレスの表示の仕方を紹介します。
書き始めるときはcurrent_user
の前に=
を忘れないでくださいね!
ユーザー名を表示 〜current_user〜
.header__left-box__list
= current_user.user
メールアドレスを表示させたい↓
.header__left-box__list
= current_user.email #nameからemailに変更
なぜ、このように
= current_user.name
や= current_user.email
のようになるかというと、、、テーブルに注目。
↓
○usersテーブル
id | name |
email |
---|---|---|
1 | mirai | [email protected] |
2 | : | : |
3 | : | : |
name
カラムやemail
カラムから引っ張ってきているのです!
=current_user
の後ろには.
を忘れず書く事!!
また、each doも同じです。
ではまた(^_^ )
おまけ
ユーザー名を表示 〜each do〜
.header__left-box__list
- @group.users.each do |hhgg|
= hhgg.name
メールアドレスを表示させたい↓
.header__left-box__list
- @group.users.each do |hhgg|
= hhgg.email #nameからemailに変更
Author And Source
この問題について(初心者!current_userの使い方 〜ログイン中のユーザ名を表示〜), 我々は、より多くの情報をここで見つけました https://qiita.com/sawayu/items/9f879b859d00d8d9e8a7著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .