LoginSignup
1
3

More than 3 years have passed since last update.

初心者!current_userの使い方 〜ログイン中のユーザ名を表示〜

Posted at

current_userでログイン中のユーザ名とメールアドレスの表示の仕方を紹介します。

書き始めるときはcurrent_userの前に=を忘れないでくださいね!

ユーザー名を表示 〜current_user〜

.header__left-box__list
  = current_user.user

スクリーンショット 2020-02-06 0.57.26.png

メールアドレスを表示させたい↓

.header__left-box__list
  = current_user.email   #nameからemailに変更

スクリーンショット 2020-02-06 0.58.08.png

なぜ、このように
= current_user.nameや= current_user.email
のようになるかというと、、、テーブルに注目。

   ↓

○usersテーブル

id name email
1 mirai mirai@mirai.com
2 : :
3 : :

nameカラムやemailカラムから引っ張ってきているのです!
=current_userの後ろには.を忘れず書く事!!

また、each doも同じです。

ではまた(^_^ )


おまけ

ユーザー名を表示 〜each do〜

.header__left-box__list
  - @group.users.each do |hhgg|
    = hhgg.name

スクリーンショット 2020-02-06 0.57.26.png

メールアドレスを表示させたい↓

.header__left-box__list
  - @group.users.each do |hhgg|
    = hhgg.email   #nameからemailに変更

スクリーンショット 2020-02-06 0.58.08.png

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