【发布时间】:2021-01-29 14:13:15
【问题描述】:
我有一个这样的多选表单:
.form-row__select
= f.collection_check_boxes(:game_ids, @games, :id, :name)
@games 集合之所以有效,是因为数据是以这种方式返回的:
=> #<Game:0x00007fa12c3a9560
id: 5,
name: :example,
active: true,
...
但现在我需要将自定义数据添加到我的集合中,但我无法使多选工作:
game = Game.enabled.includes(:category)
@games = game.map do |s|
[[s.category.name, I18n.t(s.type_code, scope: 'enum.type.name')].join(' - '), s.id]
end
@games.sort!
上述方法的结果是这样的数组数组:
[["Example one - Category X", 5],
["Example four - Category Y", 1]]
...
如何使用上面的数组进行多项选择并显示其字符串以便可以选择它们? 非常感谢您的帮助!
【问题讨论】:
标签: arrays ruby-on-rails checkbox