From f48c576fc85ab947e91ec93523951de4a2ff21bf Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Wed, 13 Jun 2012 15:49:31 -0400 Subject: Show how to add attributes to options --- guides/source/form_helpers.textile | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'guides/source') 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: + + +<%= options_for_select([['Lisbon', 1, :'data-size' => '2.8 million'], ['Madrid', 2, :'data-size' => '3.2 million']], 2) %> + +output: + + + +... + + 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+: -- cgit v1.2.3