架构:
persons (id, name, birthyear, gender)
pets (id, person_id, name, leg_count)
plants (id, person_id, kind, qty)
我想对这些按人分组的事情进行只读报告。人员列表已完成(没有相关记录)。我想每个人都有“子表”。就像是:
Persons
+----+------+-----------+--------+
| id | name | birthyear | gender |
+----+------+-----------+--------+
| 1 | Joe | 1980 | M |
+----+------+-----------+--------+
| Pets |
| +----+------+-----------+ |
| | id | name | Leg count | |
| +----+------+-----------+ |
| | 1 | Rex | 4 | |
| +----+------+-----------+ |
| | 2 | Ka | 0 | |
| +----+------+-----------+ |
| Plants |
| +----+------------+-----+ |
| | id | kind | qty | |
| +----+------------+-----+ |
| | 1 | lemon tree | 2 | |
| +----+------------+-----+ |
+----+------+-----------+--------+
| 2 | Jane | 1982 | F |
+----+------+-----------+--------+
| Pets |
| +----+------+-----------+ |
| | id | name | Leg count | |
| +----+------+-----------+ |
| | 3 | Sue | 6 | |
| +----+------+-----------+ |
| Plants |
| +----+------------+-----+ |
| | id | kind | qty | |
| +----+------------+-----+ |
| | 2 | Oak tree | 1 | |
| +----+------------+-----+ |
+----+------+-----------+--------+
你能帮我一些提示在哪里以及如何连接到框架吗?(JRuby (1.5.0)、Ruby on Rails (2.3.4)、ActiveRecord (2.3.4))
做了什么
Persons
+----+------+-----------+--------+
| id | name | birthyear | gender |
+----+------+-----------+--------+
| 1 | Joe | 1980 | M |
+----+------+-----------+--------+
| 2 | Jane | 1982 | F |
+----+------+-----------+--------+
它是使用以下方法完成的:
class PersonsReportController < PersonsController
layout 'simpreport'
active_scaffold :person do |config|
c.columns = [:name, :birthyear, :gender, :pets, :plants ]
c.label = "Report of people and other living creatures"
[:pets, :plants].each do |col|
columns[col].clear_link
end
c.list.columns.exclude :pets, :plants
c.actions.exclude :show
end
# ...
end
而且我还定制了_list_header.rhtml
, _list_column_headings.rhtml
, 和_list_actions.rhtml
一点点以消除所有交互性(如排序等)。