2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

options_for_select で disabled を指定する

Last updated at Posted at 2012-03-16

メソッドのシグネチャだけみると selected しか指定できそうにありませんが、options_for_select, options_from_collection_for_select 共に disabled も指定できます。

指定方法は、Hash で Key は、:selected, :disabled、Value は、<option> の value の配列です。

list = option_no_list
selected = ...
disabled_list = list.map {|p| p.id if p.disabled }.compact

select_tag "hoge", options_from_collection_for_select(list, "id", "name", :selected => selected.id, :disabled => disabled_list), ... %>
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?