X-Editable Rails下拉布尔值

时间:2018-03-18 12:40:35

标签: ruby-on-rails-5 x-editable

我使用X-Editable来更改布尔值。目前,下拉列表提供了两个选项,"是"并且"不"但是我想将其更改为" Active"和"无效"。

<%= 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

1 个答案:

答案 0 :(得分:2)

尝试将您的观看代码更改为:

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

github中所述:

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

可选

最好的解决方法是github

中提出的 DRY