Search code examples
ruby-on-rails-5x-editable

X-Editable Rails Dropdown Boolean Values


I'm using X-Editable to change a boolean value. Currently the dropdown gives two options, "Yes" and "No", however I would like to change that to "Active" and "Inactive".

<%= editable user, :active %>

I've tried to add the options like this:

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

However that throws the following NoMethodError:

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

Solution

  • Try change your view code to this:

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

    as mentioned in github:

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

    Optional

    The best way to this is in respect to DRY also proposed in github