User model
class User < ActiveRecord::Base
has_many :medicalhistory
end
Mdedicalhistory model
class Medicalhistory < ActiveRecord::Base
belongs_to :user #foreign key -> user_id
accepts_nested_attributes_for :user
end
Error
undefined method `lastname' for #<ActiveRecord::Relation:0xb6ad89d0>
#this works
@medicalhistory = Medicalhistory.find(current_user.id)
print "\n" + @medicalhistory.lastname
#this doesn't!
@medicalhistory = Medicalhistory.where("user_id = ?", current_user.id)
print "\n" + @medicalhistory.lastname #error on this line
@medicalhistory.first.lastnamework?findinstead ofwherefixed the issues for me