我在Rails中使用ActiveAdmin。
我的用例类似于货币兑换:假设我有10种货币,并且一种货币可以转换为另一种货币。为了支持编辑,我需要创建一个矩阵,其中行是CurrencyA,列是CurrencyB,值是从CurrencyA到CurrencyB的转换,如下所示:
| | SGD | USD | HKD | CNY |
|-----|-----|-----|-----|-----|
| SGD | | | | |
| USD | | | | |
| HKD | | | | |
| CNY | | | | |
相应地,在我的数据库中,有一个名为的表currency_conversions
,该表具有:
from_currency | to_currency | conversion_rate
(我的实际用例不是货币转换,但是此示例可以更好地显示我的用例)。
但是,我找不到activeadmin具有这种功能..有什么建议吗?
经过一番调查,我发现
这是它的样子(数据是伪造的):
这是我所做的:
app/assets/stylesheets/active_admin.css.scss
另外,由于我今天已经投票了,所以让我在这里分享我的视图代码(它是.html.slim
format);我多次重复使用它:
/ Required params:
/ - headers -- the headers array. each item would be passed to the header_blk
/ - left_headers -- the array for the headers on the left side
/ - rows -- contents for the table
/ - col_blk -- a block to get the content needed for each column, where what passed in is the:
/ column, row_id, col_id
/ Optional params:
/ - banner_top_right -- the banner text you want to put at the top-right of the splitter
/ - banner_bottom_left -- the banner text you want to put at the bottom-left of the splitter
- banner_top_right ||= ""
- banner_bottom_left ||= ""
table.admin-matrix
thead
tr
td.diagonal-splitter
svg(width='100%' height='100%')
line(x1='0' y1='0' x2='100%' y2='100%' style='stroke:rgb(0,0,0);stroke-width=2')
.triangle-top-right = banner_top_right
.triangle-bottom-left = banner_bottom_left
- headers.each do |header|
td.header
= header
tbody
- rows.each_with_index do |row, rid|
tr
td.header = left_headers[rid]
- row.each_with_index do |col, cid|
td
- col_blk[col, rid, cid]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句