On October 14, 2013 at 8:52:45 , Hillary Hueter ([email protected]) wrote:
So i have two questions: 
#1: Grouping with Associations
In my app a Trip Participant may possibly have a roommate. When the user 
selects a roommate in the GUI I save the pk id to a column i call room. 

So if two participants are roommates the rows would look like this: 
id room
1  2
2  4
3  2
4  1 

I'm trying to create an output in a table where the participants with roommates 
are grouped/sorted together. 

id  
1  
4  
3  
2

My best guess is that I need to create a query to get the data ordered this 
way, but i'm not sure how to create that query. 

There are many ways to do this. You could go with creating temp tables, you 
could sort by room (which is close, but not exactly matching your spec), etc, 
but what I would suggest is that you're abstraction is missing an object. The 
model looks like it should probably be 

Person => Room
Person (has_many | belongs_to) :room(s)
Person (has_many) :roommates, :through => :room(s)

By adding the room object and associating each person with a room you can 
define the room mates pretty easily and get an properly ordered query. 


#2
In the output i need to have an empty row between each roommate pair. Anyone 
know how to do this in the html or Prawn. 
  

You want to add the extra row on each iterator.  
<…table construction logic >
@persons.each do |person|
  <… create row with person data …>
  <… create blank row ..>
end
<… table close ..>




-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to