X-Editable Rails 下拉布尔值

X-Editable Rails Dropdown Boolean Values

我正在使用 X-Editable 更改布尔值。目前下拉菜单提供了两个选项,"Yes" 和 "No",但是我想将其更改为 "Active" 和 "Inactive"。

<%= editable user, :active %>

我试过添加这样的选项:

<%= editable user, :active, [['Active', true], ['Inactive', false]] %>

但是会抛出以下 NoMethodError:

undefined method `each_pair' for [["Active", true], ["Inactive", false]]:Array
Did you mean?  each_slice

尝试将您的视图代码更改为:

<%= editable user, :active, source: ['Active', 'Inactive'] %>

github所述:

source = [ "Active", "Disabled" ]
editable @model, :enabled, source: source

可选

关于 DRY 的最佳方法也在 github

中提出