[Solved] Display the details of only current user who is logged in? [closed]


You need to set the associations between models

After that, it could look like this:

  @students = @user.students.all

where @user = current_user

I guess.

Edit:

To make it failsafe:

@students = @user.students.all if @user

To avoid later problems set user only when its not set by the controller e.g in a user view:

@user ||= current_user

This only sets @user to current_user when it’s not already set.

0

solved Display the details of only current user who is logged in? [closed]