when rendering a view, if the object being rendered doesn’t respond to a
method it raises an error message.
For example, I have an Employee class and each employee has many Tasks.
So I may call:
<%= employee.tasks.first.task_name %>
If, for some reason an employee has 0 tasks associated with it, the
above template method would raise an exception.
Is it efficient to loop through the @employees array, with something
like:
@employees = Employee.find(:all,…).collect{|e| e if e.tasks.size >
0}.compact
Then at least the .first-ed array always has a blank Task on the end
with a
blank .name. You didn’t specify if your view should view taskless
employees.
(And shame on them for slacking!!
–
Phlip
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.