# :collection

**URL:** <https://www.ruby-forum.com/t/collection/148004>\
**Category:** Rails\
**Created:** [September 8, 2008, 8:10am UTC](https://www.ruby-forum.com/t/collection/148004 "2008-09-08T08:10:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [September 8, 2008, 8:10am UTC](https://www.ruby-forum.com/t/collection/148004/1 "2008-09-08T08:10:56Z")

</div>

Hi  
I am calling the following from the problem controller  
@problem=Problem.find(params[:id])  
MailSendingProblem.send\_mail\_to\_group\_owner(group\_id.to\_i,@problem) and  
inside the def send\_mail\_to\_group\_owner

ProblemMailer.deliver\_to\_send\_mail\_to\_user(user.name,pemailaddress.email,problem)

```
 Now in the view to_send_mail_to_user.rhtml I have

```

Number : \<%= @problem.number%\>  
Title : \<%= @problem.title%\>  
Urgency : \<%=h ProblemUrgency.find(@problem.problem\_urgency\_id).name  
if !@problem.problem\_urgency\_id==nil?%\>

Priority : \<%=h  
ProblemPriority.find(@problem.problem\_priority\_id).name if  
!@problem.problem\_priority\_id==nil?%\>

```
   I have heard about collection but not yet used.What I am asking

```

is that in the above Urgency and priority from the view the db is  
queried directly…So can i avoid this and pass the data as collections  
(I dont know I am right) from controller and access it in view so that  
avoid direct querying of datbase from view ? Or if I conntinue with the  
above is it wrong?

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [September 8, 2008, 9:16am UTC](https://www.ruby-forum.com/t/collection/148004/2 "2008-09-08T09:16:46Z")

</div>

On Sep 8, 7:10 am, Sijo Kg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Title : \<%= @problem.title%\>  
> Urgency : \<%=h ProblemUrgency.find(@problem.problem\_urgency\_id).name  
> if !removed\_email\_address@domain.invalid\_urgency\_id==nil?%\>
> 
> Priority : \<%=h  
> ProblemPriority.find(@problem.problem\_priority\_id).name if  
> !removed\_email\_address@domain.invalid\_priority\_id==nil?%\>

Given the time you;ve been posting to this list you should really have  
read about associations.  
Give problem a problem\_urgency (or even just urgency) association and  
the lines above become things like

@problem.problem\_urgency.name if @problem.problem\_urgency

Not sure what collections have got to do with any of this.  
Fred
