aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/form_helpers.textile
diff options
context:
space:
mode:
authorNathan Long <nathan.long@tma1.com>2012-06-13 15:49:31 -0400
committerNathan Long <nathan.long@tma1.com>2012-06-13 15:49:31 -0400
commitf48c576fc85ab947e91ec93523951de4a2ff21bf (patch)
treea1df6047d38a005bd904162cde983843c897a685 /guides/source/form_helpers.textile
parent18faa5b3375daa2b090a360e4a24649f9a4e03d2 (diff)
downloadrails-f48c576fc85ab947e91ec93523951de4a2ff21bf.tar.gz
rails-f48c576fc85ab947e91ec93523951de4a2ff21bf.tar.bz2
rails-f48c576fc85ab947e91ec93523951de4a2ff21bf.zip
Show how to add attributes to options
Diffstat (limited to 'guides/source/form_helpers.textile')
-rw-r--r--guides/source/form_helpers.textile12
1 files changed, 12 insertions, 0 deletions
diff --git a/guides/source/form_helpers.textile b/guides/source/form_helpers.textile
index 8106de6f9d..1851aceff8 100644
--- a/guides/source/form_helpers.textile
+++ b/guides/source/form_helpers.textile
@@ -419,6 +419,18 @@ TIP: The second argument to +options_for_select+ must be exactly equal to the de
WARNING: when +:inlude_blank+ or +:prompt:+ are not present, +:include_blank+ is forced true if the select attribute +required+ is true, display +size+ is one and +multiple+ is not true.
+You can add arbitrary attributes to the options using hashes:
+
+<erb>
+<%= options_for_select([['Lisbon', 1, :'data-size' => '2.8 million'], ['Madrid', 2, :'data-size' => '3.2 million']], 2) %>
+
+output:
+
+<option value="1" data-size="2.8 million">Lisbon</option>
+<option value="2" selected="selected" data-size="3.2 million">Madrid</option>
+...
+</erb>
+
h4. Select Boxes for Dealing with Models
In most cases form controls will be tied to a specific database model and as you might expect Rails provides helpers tailored for that purpose. Consistent with other form helpers, when dealing with models you drop the +_tag+ suffix from +select_tag+: