Do all your Profiles have a user_id
value? You might want to consider doing the following to verify that user_id
is present for all Profiles:
Profile.pluck :user_id
I suspect a profile object/record does not have a user_id
and hence traversing via profile.user.profile_name
renders the nil class error.