i have aulas , students through grades,
in grades want display name of student , name of aula.
<% @grades.each |grade| %> <%= grade.student.name %> <%= grade.aula.name %> <% end %>
if leave student perfect, when want aula name, get:
undefined method `aula' #<#<class:0x30a37e8>:0x2fffeb0>
here code
class aula < activerecord::base attr_accessible :name has_many :grades has_many :students, :through => :grades end class student < activerecord::base attr_accessible :name has_many :grades has_many :aulas, :through => :grades end class grade < activerecord::base attr_accessible :grammar, :oral, :participation, :writing belongs_to :aula belongs_to :student end
i figure problem if grade.aula.name
nil, error. if data there, works perfectly.
how can action like, if grade.aula.name.nill? grade.aula.name = 'write name here'
?
Comments
Post a Comment