I am trying to then access "students_last_subject_id" using several
methods including @profile.students_last_subject_id,
but it keeps returning nil. With the enclosing brackets i am guessing
this is not a hash..
Nope. where returns an array containing all the records it finds, even if
it's only one. If you know, or at least are pretty sure, your search will
only give one row object, you can use find_by, or just pull the first
element from the where's array:
Also, assuming you have setup your relationships correctly (so profile
belongs_to user, user has_many profiles) then you should be able to do
@profile = current_user.profiles.first
or if you have user has_one profile then
@profile = current_user.profile