modelo de usuariométodo no definido de ActiveRecord :: Relation
class User < ActiveRecord::Base
has_many :medicalhistory
end
modelo Mdedicalhistory
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
¿cuál es el mensaje de error? –
¿Funciona '@ medicalhistory.first.lastname'? – Zabba
:(sí que lo hace .... insight? – Omnipresent