Read more

Rails: Disable options of a select field

Dominik Schöler
August 02, 2013Software engineer at makandra GmbH

Simply give the select helper an option :disabled, passing either a single value or an array. You need to specify the option's value, not its text.

= form.select :country, Address.countries_for_select, :include_blank => true, :disabled => ['disabled-value1', 'disabled-value-2']

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Also see Cucumber: Check if a select field contains a disabled option on how to test this.

Posted by Dominik Schöler to makandra dev (2013-08-02 08:42)