RoR:子记录列表
架构:
人员(身份证、姓名、出生年份、性别)
宠物(id,person_id,名称,leg_count)
植物(id,person_id,种类,数量)
我想制作一份关于按人员分组的这些事物的只读报告。人员清单已完成(没有相关记录)。我想要每人都有“子表”。例如:
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< /code>、
_list_column_headings.rhtml
和 _list_actions.rhtml
一点点,以消除所有交互性(如排序等)。
Schema:
persons (id, name, birthyear, gender)
pets (id, person_id, name, leg_count)
plants (id, person_id, kind, qty)
I would like to make a read-only report about these things grouped by persons. The listing of personns is done (without the associated records). I would like to have "subtables" per persons. Something like:
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 | |
| +----+------------+-----+ |
+----+------+-----------+--------+
Can you please help me with some tips where and how to hook to the framework? (JRuby (1.5.0), Ruby on Rails (2.3.4), ActiveRecord (2.3.4) )
What is done
Persons
+----+------+-----------+--------+
| id | name | birthyear | gender |
+----+------+-----------+--------+
| 1 | Joe | 1980 | M |
+----+------+-----------+--------+
| 2 | Jane | 1982 | F |
+----+------+-----------+--------+
It is done using:
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
And I also customized _list_header.rhtml
, _list_column_headings.rhtml
, and _list_actions.rhtml
a little bit in order to kill all interactivity (like orderings and so on).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白你在控制器中编写的代码,也不明白为什么它继承自你的 PersonsController。也许你可以多解释一下你想在那里完成什么?
话虽这么说,我会这样解决你的问题:
Models:
person.rb:
pet.rb:
plant.rb:
Controller:
reports_controller.rb:
View :
报告/index.html.erb:
I don't understand the code you have written in your controller, nor why it inherits from your PersonsController. Maybe you can explain a bit more what you are trying to accomplish there?
That being said, I would solve your problem like this:
Models:
person.rb:
pet.rb:
plant.rb:
Controller:
reports_controller.rb:
View:
reports/index.html.erb:
这是在 ActiveScaffold 中工作的解决方案:
app/controllers/people_controller.rb
现在,报表打开,子表折叠起来,因此我们必须使用 event.simulate.js 来自 远大的。
下载 protolicious 并将 event.simulate.js 复制到您的 public/javascripts 目录。
现在,在布局中包含 event.simulate.js:
并将此脚本标记添加到视图底部:
给定以下模型
app/models/person.rb
app/models/pet.rb
app/models/plant.rb
Here's a solution that works inside ActiveScaffold:
app/controllers/people_controller.rb
Now the report opens up with the child tables collapsed, so we have to expand them using event.simulate.js from protolicious.
Download protolicious and copy event.simulate.js to your public/javascripts directory.
Now include event.simulate.js in your layout:
And add this script tag to the bottom of your view:
Given the following models
app/models/person.rb
app/models/pet.rb
app/models/plant.rb