Oliver Fox wrote:
> <%= employee.tasks.first.task_name %>
>
> If, for some reason an employee has 0 tasks associated with it, the
...> @employees = Employee.find(:all,...).collect{|e| e if e.tasks.size >
> 0}.compact
Your controller is not controlling your view enough! To present only employees
with tasks, try this abomination:
Employee.find(:all).select{|e| e.tasks.any? }
That''s the same as yours, but it uses select.
If that melts your database server, try some variation on:
Employee.find(:all, :include => :tasks,
:conditions => ''tasks.id is not null'')
There might be better or alternate ways. Another one is this:
<%= (employee.tasks + [Task.new]).first.task_name %>
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---