Guest User

Untitled

a guest
Mar 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. def matrix_for(collection,row_attribute,col_attribute,display_attribute)
  2. returnstring = "<table>\n"
  3. returnstring += ([" <tr>\n <td>\n"] + entries_for(collection,col_attribute)).join("\n </td>\n <td>\n") + "\n </td>\n </tr>\n"
  4. entries_for(collection,row_attribute).each do |row|
  5. r = [" <tr>\n <td>\n#{row}"]
  6. entries_for(collection,col_attribute).each do |column|
  7. r << collection.select{|p| p.send(col_attribute) == column && p.send(row_attribute) == row}.map{|p| p.send(display_attribute)}.join("<br/>\n")
  8. end
  9. returnstring += r.join("\n </td>\n <td>") + "\n </td>\n </tr>\n"
  10. end
  11. returnstring + "</table>"
  12. end
Add Comment
Please, Sign In to add comment