rails 4.2.0.beta3 → 4.2.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -7
  3. data/guides/output/2_2_release_notes.html +724 -0
  4. data/guides/output/2_3_release_notes.html +870 -0
  5. data/guides/output/3_0_release_notes.html +773 -0
  6. data/guides/output/3_1_release_notes.html +740 -0
  7. data/guides/output/3_2_release_notes.html +797 -0
  8. data/guides/output/4_0_release_notes.html +523 -0
  9. data/guides/output/4_1_release_notes.html +806 -0
  10. data/guides/output/4_2_release_notes.html +728 -0
  11. data/guides/output/Gemfile +6 -0
  12. data/guides/output/_license.html +226 -0
  13. data/guides/output/_welcome.html +233 -0
  14. data/guides/output/action_controller_overview.html +1335 -0
  15. data/guides/output/action_mailer_basics.html +928 -0
  16. data/guides/output/action_view_overview.html +1509 -0
  17. data/guides/output/active_job_basics.html +546 -0
  18. data/guides/output/active_model_basics.html +438 -0
  19. data/guides/output/active_record_basics.html +594 -0
  20. data/guides/output/active_record_callbacks.html +592 -0
  21. data/guides/output/active_record_migrations.html +1123 -0
  22. data/guides/output/active_record_postgresql.html +675 -0
  23. data/guides/output/active_record_querying.html +1796 -0
  24. data/guides/output/active_record_validations.html +1301 -0
  25. data/guides/output/active_support_core_extensions.html +3450 -0
  26. data/guides/output/active_support_instrumentation.html +1121 -0
  27. data/guides/output/api_documentation_guidelines.html +498 -0
  28. data/guides/output/asset_pipeline.html +1167 -0
  29. data/guides/output/association_basics.html +2086 -0
  30. data/guides/output/caching_with_rails.html +553 -0
  31. data/guides/output/command_line.html +791 -0
  32. data/guides/output/configuring.html +1055 -0
  33. data/guides/output/contributing_to_ruby_on_rails.html +657 -0
  34. data/guides/output/credits.html +284 -0
  35. data/guides/output/debugging_rails_applications.html +1014 -0
  36. data/guides/output/development_dependencies_install.html +478 -0
  37. data/guides/output/engines.html +1438 -0
  38. data/guides/output/form_helpers.html +1074 -0
  39. data/guides/output/generators.html +838 -0
  40. data/guides/output/getting_started.html +2092 -0
  41. data/guides/output/i18n.html +1198 -0
  42. data/guides/output/images/akshaysurve.jpg +0 -0
  43. data/guides/output/images/belongs_to.png +0 -0
  44. data/guides/output/images/book_icon.gif +0 -0
  45. data/guides/output/images/bullet.gif +0 -0
  46. data/guides/output/images/chapters_icon.gif +0 -0
  47. data/guides/output/images/check_bullet.gif +0 -0
  48. data/guides/output/images/credits_pic_blank.gif +0 -0
  49. data/guides/output/images/csrf.png +0 -0
  50. data/guides/output/images/edge_badge.png +0 -0
  51. data/guides/output/images/favicon.ico +0 -0
  52. data/guides/output/images/feature_tile.gif +0 -0
  53. data/guides/output/images/footer_tile.gif +0 -0
  54. data/guides/output/images/fxn.png +0 -0
  55. data/guides/output/images/getting_started/article_with_comments.png +0 -0
  56. data/guides/output/images/getting_started/challenge.png +0 -0
  57. data/guides/output/images/getting_started/confirm_dialog.png +0 -0
  58. data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  59. data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  60. data/guides/output/images/getting_started/form_with_errors.png +0 -0
  61. data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
  62. data/guides/output/images/getting_started/new_article.png +0 -0
  63. data/guides/output/images/getting_started/new_post.png +0 -0
  64. data/guides/output/images/getting_started/post_with_comments.png +0 -0
  65. data/guides/output/images/getting_started/rails_welcome.png +0 -0
  66. data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
  67. data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
  68. data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
  69. data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
  70. data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
  71. data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
  72. data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
  73. data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
  74. data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
  75. data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
  76. data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
  77. data/guides/output/images/grey_bullet.gif +0 -0
  78. data/guides/output/images/habtm.png +0 -0
  79. data/guides/output/images/has_many.png +0 -0
  80. data/guides/output/images/has_many_through.png +0 -0
  81. data/guides/output/images/has_one.png +0 -0
  82. data/guides/output/images/has_one_through.png +0 -0
  83. data/guides/output/images/header_backdrop.png +0 -0
  84. data/guides/output/images/header_tile.gif +0 -0
  85. data/guides/output/images/i18n/demo_html_safe.png +0 -0
  86. data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
  87. data/guides/output/images/i18n/demo_translated_en.png +0 -0
  88. data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
  89. data/guides/output/images/i18n/demo_translation_missing.png +0 -0
  90. data/guides/output/images/i18n/demo_untranslated.png +0 -0
  91. data/guides/output/images/icons/README +5 -0
  92. data/guides/output/images/icons/callouts/1.png +0 -0
  93. data/guides/output/images/icons/callouts/10.png +0 -0
  94. data/guides/output/images/icons/callouts/11.png +0 -0
  95. data/guides/output/images/icons/callouts/12.png +0 -0
  96. data/guides/output/images/icons/callouts/13.png +0 -0
  97. data/guides/output/images/icons/callouts/14.png +0 -0
  98. data/guides/output/images/icons/callouts/15.png +0 -0
  99. data/guides/output/images/icons/callouts/2.png +0 -0
  100. data/guides/output/images/icons/callouts/3.png +0 -0
  101. data/guides/output/images/icons/callouts/4.png +0 -0
  102. data/guides/output/images/icons/callouts/5.png +0 -0
  103. data/guides/output/images/icons/callouts/6.png +0 -0
  104. data/guides/output/images/icons/callouts/7.png +0 -0
  105. data/guides/output/images/icons/callouts/8.png +0 -0
  106. data/guides/output/images/icons/callouts/9.png +0 -0
  107. data/guides/output/images/icons/caution.png +0 -0
  108. data/guides/output/images/icons/example.png +0 -0
  109. data/guides/output/images/icons/home.png +0 -0
  110. data/guides/output/images/icons/important.png +0 -0
  111. data/guides/output/images/icons/next.png +0 -0
  112. data/guides/output/images/icons/note.png +0 -0
  113. data/guides/output/images/icons/prev.png +0 -0
  114. data/guides/output/images/icons/tip.png +0 -0
  115. data/guides/output/images/icons/up.png +0 -0
  116. data/guides/output/images/icons/warning.png +0 -0
  117. data/guides/output/images/nav_arrow.gif +0 -0
  118. data/guides/output/images/oscardelben.jpg +0 -0
  119. data/guides/output/images/polymorphic.png +0 -0
  120. data/guides/output/images/radar.png +0 -0
  121. data/guides/output/images/rails4_features.png +0 -0
  122. data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
  123. data/guides/output/images/rails_guides_logo.gif +0 -0
  124. data/guides/output/images/rails_logo_remix.gif +0 -0
  125. data/guides/output/images/session_fixation.png +0 -0
  126. data/guides/output/images/tab_grey.gif +0 -0
  127. data/guides/output/images/tab_info.gif +0 -0
  128. data/guides/output/images/tab_note.gif +0 -0
  129. data/guides/output/images/tab_red.gif +0 -0
  130. data/guides/output/images/tab_yellow.gif +0 -0
  131. data/guides/output/images/tab_yellow.png +0 -0
  132. data/guides/output/images/vijaydev.jpg +0 -0
  133. data/guides/output/index.html +354 -0
  134. data/guides/output/initialization.html +876 -0
  135. data/guides/output/javascripts/guides.js +59 -0
  136. data/guides/output/javascripts/jquery.min.js +4 -0
  137. data/guides/output/javascripts/responsive-tables.js +43 -0
  138. data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
  139. data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
  140. data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
  141. data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
  142. data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
  143. data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
  144. data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
  145. data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
  146. data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
  147. data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
  148. data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
  149. data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
  150. data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
  151. data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
  152. data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
  153. data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
  154. data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
  155. data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
  156. data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
  157. data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
  158. data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
  159. data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
  160. data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
  161. data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
  162. data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
  163. data/guides/output/javascripts/syntaxhighlighter/shCore.js +17 -0
  164. data/guides/output/layout.html +448 -0
  165. data/guides/output/layouts_and_rendering.html +1541 -0
  166. data/guides/output/maintenance_policy.html +257 -0
  167. data/guides/output/migrations.html +1360 -0
  168. data/guides/output/nested_model_forms.html +412 -0
  169. data/guides/output/plugins.html +644 -0
  170. data/guides/output/rails_application_templates.html +450 -0
  171. data/guides/output/rails_on_rack.html +547 -0
  172. data/guides/output/routing.html +1631 -0
  173. data/guides/output/ruby_on_rails_guides_guidelines.html +329 -0
  174. data/guides/output/security.html +935 -0
  175. data/guides/output/stylesheets/fixes.css +16 -0
  176. data/guides/output/stylesheets/kindle.css +11 -0
  177. data/guides/output/stylesheets/main.css +713 -0
  178. data/guides/output/stylesheets/print.css +52 -0
  179. data/guides/output/stylesheets/reset.css +43 -0
  180. data/guides/output/stylesheets/responsive-tables.css +50 -0
  181. data/guides/output/stylesheets/style.css +13 -0
  182. data/guides/output/stylesheets/syntaxhighlighter/shCore.css +226 -0
  183. data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
  184. data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
  185. data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
  186. data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
  187. data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  188. data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
  189. data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
  190. data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
  191. data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
  192. data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
  193. data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
  194. data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
  195. data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  196. data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
  197. data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
  198. data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
  199. data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
  200. data/guides/output/testing.html +1350 -0
  201. data/guides/output/upgrading_ruby_on_rails.html +1135 -0
  202. data/guides/output/working_with_javascript_in_rails.html +587 -0
  203. data/guides/source/4_0_release_notes.md +2 -2
  204. data/guides/source/4_2_release_notes.md +9 -2
  205. data/guides/source/action_controller_overview.md +3 -1
  206. data/guides/source/action_mailer_basics.md +1 -2
  207. data/guides/source/active_job_basics.md +25 -2
  208. data/guides/source/active_model_basics.md +350 -19
  209. data/guides/source/active_record_basics.md +2 -2
  210. data/guides/source/active_record_migrations.md +1 -1
  211. data/guides/source/active_record_validations.md +12 -4
  212. data/guides/source/active_support_core_extensions.md +7 -9
  213. data/guides/source/active_support_instrumentation.md +2 -0
  214. data/guides/source/association_basics.md +7 -7
  215. data/guides/source/configuring.md +24 -0
  216. data/guides/source/contributing_to_ruby_on_rails.md +1 -1
  217. data/guides/source/credits.html.erb +1 -1
  218. data/guides/source/documents.yaml +5 -0
  219. data/guides/source/engines.md +2 -2
  220. data/guides/source/form_helpers.md +6 -0
  221. data/guides/source/i18n.md +6 -9
  222. data/guides/source/layouts_and_rendering.md +1 -1
  223. data/guides/source/plugins.md +2 -2
  224. data/guides/source/rails_on_rack.md +4 -0
  225. data/guides/source/testing.md +1 -0
  226. data/guides/source/upgrading_ruby_on_rails.md +5 -5
  227. metadata +227 -27
@@ -0,0 +1,1074 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
7
+
8
+ <title>Form Helpers — Ruby on Rails Guides</title>
9
+ <link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
10
+ <link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
11
+
12
+ <link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
13
+ <link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
14
+
15
+ <link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
16
+
17
+ <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
18
+ </head>
19
+ <body class="guide">
20
+ <div id="topNav">
21
+ <div class="wrapper">
22
+ <strong class="more-info-label">More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
23
+ <span class="red-button more-info-button">
24
+ More Ruby on Rails
25
+ </span>
26
+ <ul class="more-info-links s-hidden">
27
+ <li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
28
+ <li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
29
+ <li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
30
+ <li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
31
+ <li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
32
+ <li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
33
+ <li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
34
+ <li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
35
+ </ul>
36
+ </div>
37
+ </div>
38
+ <div id="header">
39
+ <div class="wrapper clearfix">
40
+ <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
41
+ <ul class="nav">
42
+ <li><a class="nav-item" href="index.html">Home</a></li>
43
+ <li class="guides-index guides-index-large">
44
+ <a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guides Index</a>
45
+ <div id="guides" class="clearfix" style="display: none;">
46
+ <hr />
47
+ <dl class="L">
48
+ <dt>Start Here</dt>
49
+ <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
50
+ <dt>Models</dt>
51
+ <dd><a href="active_record_basics.html">Active Record Basics</a></dd>
52
+ <dd><a href="active_record_migrations.html">Active Record Migrations</a></dd>
53
+ <dd><a href="active_record_validations.html">Active Record Validations</a></dd>
54
+ <dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd>
55
+ <dd><a href="association_basics.html">Active Record Associations</a></dd>
56
+ <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
57
+ <dt>Views</dt>
58
+ <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
59
+ <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
60
+ <dt>Controllers</dt>
61
+ <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
62
+ <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
63
+ </dl>
64
+ <dl class="R">
65
+ <dt>Digging Deeper</dt>
66
+ <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
67
+ <dd><a href="i18n.html">Rails Internationalization API</a></dd>
68
+ <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
69
+ <dd><a href="active_job_basics.html">Active Job Basics</a></dd>
70
+ <dd><a href="security.html">Securing Rails Applications</a></dd>
71
+ <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
72
+ <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
73
+ <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
74
+ <dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
75
+ <dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd>
76
+ <dt>Extending Rails</dt>
77
+ <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
78
+ <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
79
+ <dt>Contributing to Ruby on Rails</dt>
80
+ <dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
81
+ <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
82
+ <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
83
+ <dt>Maintenance Policy</dt>
84
+ <dd><a href="maintenance_policy.html">Maintenance Policy</a></dd>
85
+ <dt>Release Notes</dt>
86
+ <dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd>
87
+ <dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</a></dd>
88
+ <dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</a></dd>
89
+ <dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</a></dd>
90
+ <dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
91
+ <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
92
+ <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
93
+ <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
94
+ </dl>
95
+ </div>
96
+ </li>
97
+ <li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li>
98
+ <li><a class="nav-item" href="credits.html">Credits</a></li>
99
+ <li class="guides-index guides-index-small">
100
+ <select class="guides-index-item nav-item">
101
+ <option value="index.html">Guides Index</option>
102
+ <optgroup label="Start Here">
103
+ <option value="getting_started.html">Getting Started with Rails</option>
104
+ </optgroup>
105
+ <optgroup label="Models">
106
+ <option value="active_record_basics.html">Active Record Basics</option>
107
+ <option value="active_record_migrations.html">Active Record Migrations</option>
108
+ <option value="active_record_validations.html">Active Record Validations</option>
109
+ <option value="active_record_callbacks.html">Active Record Callbacks</option>
110
+ <option value="association_basics.html">Active Record Associations</option>
111
+ <option value="active_record_querying.html">Active Record Query Interface</option>
112
+ </optgroup>
113
+ <optgroup label="Views">
114
+ <option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option>
115
+ <option value="form_helpers.html">Action View Form Helpers</option>
116
+ </optgroup>
117
+ <optgroup label="Controllers">
118
+ <option value="action_controller_overview.html">Action Controller Overview</option>
119
+ <option value="routing.html">Rails Routing from the Outside In</option>
120
+ </optgroup>
121
+ <optgroup label="Digging Deeper">
122
+ <option value="active_support_core_extensions.html">Active Support Core Extensions</option>
123
+ <option value="i18n.html">Rails Internationalization API</option>
124
+ <option value="action_mailer_basics.html">Action Mailer Basics</option>
125
+ <option value="active_job_basics.html">Active Job Basics</option>
126
+ <option value="security.html">Securing Rails Applications</option>
127
+ <option value="debugging_rails_applications.html">Debugging Rails Applications</option>
128
+ <option value="configuring.html">Configuring Rails Applications</option>
129
+ <option value="command_line.html">Rails Command Line Tools and Rake Tasks</option>
130
+ <option value="asset_pipeline.html">Asset Pipeline</option>
131
+ <option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option>
132
+ </optgroup>
133
+ <optgroup label="Extending Rails">
134
+ <option value="rails_on_rack.html">Rails on Rack</option>
135
+ <option value="generators.html">Creating and Customizing Rails Generators</option>
136
+ </optgroup>
137
+ <optgroup label="Contributing to Ruby on Rails">
138
+ <option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option>
139
+ <option value="api_documentation_guidelines.html">API Documentation Guidelines</option>
140
+ <option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</option>
141
+ </optgroup>
142
+ <optgroup label="Maintenance Policy">
143
+ <option value="maintenance_policy.html">Maintenance Policy</option>
144
+ </optgroup>
145
+ <optgroup label="Release Notes">
146
+ <option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option>
147
+ <option value="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</option>
148
+ <option value="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</option>
149
+ <option value="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</option>
150
+ <option value="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</option>
151
+ <option value="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</option>
152
+ <option value="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</option>
153
+ <option value="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</option>
154
+ </optgroup>
155
+ </select>
156
+ </li>
157
+ </ul>
158
+ </div>
159
+ </div>
160
+ <hr class="hide" />
161
+
162
+ <div id="feature">
163
+ <div class="wrapper">
164
+ <h2>Form Helpers</h2><p>Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of the need to handle form control naming and its numerous attributes. Rails does away with this complexity by providing view helpers for generating form markup. However, since these helpers have different use cases, developers need to know the differences between the helper methods before putting them to use.</p><p>After reading this guide, you will know:</p>
165
+ <ul>
166
+ <li>How to create search forms and similar kind of generic forms not representing any specific model in your application.</li>
167
+ <li>How to make model-centric forms for creating and editing specific database records.</li>
168
+ <li>How to generate select boxes from multiple types of data.</li>
169
+ <li>What date and time helpers Rails provides.</li>
170
+ <li>What makes a file upload form different.</li>
171
+ <li>How to post forms to external resources and specify setting an <code>authenticity_token</code>.</li>
172
+ <li>How to build complex forms.</li>
173
+ </ul>
174
+
175
+
176
+ <div id="subCol">
177
+ <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
178
+ <ol class="chapters">
179
+ <li>
180
+ <a href="#dealing-with-basic-forms">Dealing with Basic Forms</a>
181
+
182
+ <ul>
183
+ <li><a href="#a-generic-search-form">A Generic Search Form</a></li>
184
+ <li><a href="#multiple-hashes-in-form-helper-calls">Multiple Hashes in Form Helper Calls</a></li>
185
+ <li><a href="#helpers-for-generating-form-elements">Helpers for Generating Form Elements</a></li>
186
+ <li><a href="#other-helpers-of-interest">Other Helpers of Interest</a></li>
187
+ </ul>
188
+ </li>
189
+ <li>
190
+ <a href="#dealing-with-model-objects">Dealing with Model Objects</a>
191
+
192
+ <ul>
193
+ <li><a href="#dealing-with-model-objects-model-object-helpers">Model Object Helpers</a></li>
194
+ <li><a href="#binding-a-form-to-an-object">Binding a Form to an Object</a></li>
195
+ <li><a href="#relying-on-record-identification">Relying on Record Identification</a></li>
196
+ <li><a href="#how-do-forms-with-patch,-put,-or-delete-methods-work-questionmark">How do forms with PATCH, PUT, or DELETE methods work?</a></li>
197
+ </ul>
198
+ </li>
199
+ <li>
200
+ <a href="#making-select-boxes-with-ease">Making Select Boxes with Ease</a>
201
+
202
+ <ul>
203
+ <li><a href="#the-select-and-option-tags">The Select and Option Tags</a></li>
204
+ <li><a href="#select-boxes-for-dealing-with-models">Select Boxes for Dealing with Models</a></li>
205
+ <li><a href="#option-tags-from-a-collection-of-arbitrary-objects">Option Tags from a Collection of Arbitrary Objects</a></li>
206
+ <li><a href="#time-zone-and-country-select">Time Zone and Country Select</a></li>
207
+ </ul>
208
+ </li>
209
+ <li>
210
+ <a href="#using-date-and-time-form-helpers">Using Date and Time Form Helpers</a>
211
+
212
+ <ul>
213
+ <li><a href="#barebones-helpers">Barebones Helpers</a></li>
214
+ <li><a href="#using-date-and-time-form-helpers-model-object-helpers">Model Object Helpers</a></li>
215
+ <li><a href="#common-options">Common Options</a></li>
216
+ <li><a href="#individual-components">Individual Components</a></li>
217
+ </ul>
218
+ </li>
219
+ <li>
220
+ <a href="#uploading-files">Uploading Files</a>
221
+
222
+ <ul>
223
+ <li><a href="#what-gets-uploaded">What Gets Uploaded</a></li>
224
+ <li><a href="#dealing-with-ajax">Dealing with Ajax</a></li>
225
+ </ul>
226
+ </li>
227
+ <li><a href="#customizing-form-builders">Customizing Form Builders</a></li>
228
+ <li>
229
+ <a href="#understanding-parameter-naming-conventions">Understanding Parameter Naming Conventions</a>
230
+
231
+ <ul>
232
+ <li><a href="#basic-structures">Basic Structures</a></li>
233
+ <li><a href="#combining-them">Combining Them</a></li>
234
+ <li><a href="#using-form-helpers">Using Form Helpers</a></li>
235
+ </ul>
236
+ </li>
237
+ <li><a href="#forms-to-external-resources">Forms to External Resources</a></li>
238
+ <li>
239
+ <a href="#building-complex-forms">Building Complex Forms</a>
240
+
241
+ <ul>
242
+ <li><a href="#configuring-the-model">Configuring the Model</a></li>
243
+ <li><a href="#nested-forms">Nested Forms</a></li>
244
+ <li><a href="#the-controller">The Controller</a></li>
245
+ <li><a href="#removing-objects">Removing Objects</a></li>
246
+ <li><a href="#preventing-empty-records">Preventing Empty Records</a></li>
247
+ <li><a href="#adding-fields-on-the-fly">Adding Fields on the Fly</a></li>
248
+ </ul>
249
+ </li>
250
+ </ol>
251
+
252
+ </div>
253
+
254
+ </div>
255
+ </div>
256
+
257
+ <div id="container">
258
+ <div class="wrapper">
259
+ <div id="mainCol">
260
+ <div class="note"><p>This guide is not intended to be a complete documentation of available form helpers and their arguments. Please visit <a href="http://api.rubyonrails.org/">the Rails API documentation</a> for a complete reference.</p></div><h3 id="dealing-with-basic-forms">1 Dealing with Basic Forms</h3><p>The most basic form helper is <code>form_tag</code>.</p><div class="code_container">
261
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
262
+ &lt;%= form_tag do %&gt;
263
+ Form contents
264
+ &lt;% end %&gt;
265
+
266
+ </pre>
267
+ </div>
268
+ <p>When called without arguments like this, it creates a <code>&lt;form&gt;</code> tag which, when submitted, will POST to the current page. For instance, assuming the current page is <code>/home/index</code>, the generated HTML will look like this (some line breaks added for readability):</p><div class="code_container">
269
+ <pre class="brush: xml; gutter: false; toolbar: false">
270
+ &lt;form accept-charset="UTF-8" action="/" method="post"&gt;
271
+ &lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;
272
+ &lt;input name="authenticity_token" type="hidden" value="J7CBxfHalt49OSHp27hblqK20c9PgwJ108nDHX/8Cts=" /&gt;
273
+ Form contents
274
+ &lt;/form&gt;
275
+
276
+ </pre>
277
+ </div>
278
+ <p>You'll notice that the HTML contains <code>input</code> element with type <code>hidden</code>. This <code>input</code> is important, because the form cannot be successfully submitted without it. The hidden input element has name attribute of <code>utf8</code> enforces browsers to properly respect your form's character encoding and is generated for all forms whether their actions are "GET" or "POST". The second input element with name <code>authenticity_token</code> is a security feature of Rails called <strong>cross-site request forgery protection</strong>, and form helpers generate it for every non-GET form (provided that this security feature is enabled). You can read more about this in the <a href="security.html#cross-site-request-forgery-csrf">Security Guide</a>.</p><h4 id="a-generic-search-form">1.1 A Generic Search Form</h4><p>One of the most basic forms you see on the web is a search form. This form contains:</p>
279
+ <ul>
280
+ <li>a form element with "GET" method,</li>
281
+ <li>a label for the input,</li>
282
+ <li>a text input element, and</li>
283
+ <li>a submit element.</li>
284
+ </ul>
285
+ <p>To create this form you will use <code>form_tag</code>, <code>label_tag</code>, <code>text_field_tag</code>, and <code>submit_tag</code>, respectively. Like this:</p><div class="code_container">
286
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
287
+ &lt;%= form_tag("/search", method: "get") do %&gt;
288
+ &lt;%= label_tag(:q, "Search for:") %&gt;
289
+ &lt;%= text_field_tag(:q) %&gt;
290
+ &lt;%= submit_tag("Search") %&gt;
291
+ &lt;% end %&gt;
292
+
293
+ </pre>
294
+ </div>
295
+ <p>This will generate the following HTML:</p><div class="code_container">
296
+ <pre class="brush: xml; gutter: false; toolbar: false">
297
+ &lt;form accept-charset="UTF-8" action="/search" method="get"&gt;
298
+ &lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;
299
+ &lt;label for="q"&gt;Search for:&lt;/label&gt;
300
+ &lt;input id="q" name="q" type="text" /&gt;
301
+ &lt;input name="commit" type="submit" value="Search" /&gt;
302
+ &lt;/form&gt;
303
+
304
+ </pre>
305
+ </div>
306
+ <div class="info"><p>For every form input, an ID attribute is generated from its name (<code>"q"</code> in above example). These IDs can be very useful for CSS styling or manipulation of form controls with JavaScript.</p></div><p>Besides <code>text_field_tag</code> and <code>submit_tag</code>, there is a similar helper for <em>every</em> form control in HTML.</p><div class="warning"><p>Always use "GET" as the method for search forms. This allows users to bookmark a specific search and get back to it. More generally Rails encourages you to use the right HTTP verb for an action.</p></div><h4 id="multiple-hashes-in-form-helper-calls">1.2 Multiple Hashes in Form Helper Calls</h4><p>The <code>form_tag</code> helper accepts 2 arguments: the path for the action and an options hash. This hash specifies the method of form submission and HTML options such as the form element's class.</p><p>As with the <code>link_to</code> helper, the path argument doesn't have to be a string; it can be a hash of URL parameters recognizable by Rails' routing mechanism, which will turn the hash into a valid URL. However, since both arguments to <code>form_tag</code> are hashes, you can easily run into a problem if you would like to specify both. For instance, let's say you write this:</p><div class="code_container">
307
+ <pre class="brush: ruby; gutter: false; toolbar: false">
308
+ form_tag(controller: "people", action: "search", method: "get", class: "nifty_form")
309
+ # =&gt; '&lt;form accept-charset="UTF-8" action="/people/search?method=get&amp;class=nifty_form" method="post"&gt;'
310
+
311
+ </pre>
312
+ </div>
313
+ <p>Here, <code>method</code> and <code>class</code> are appended to the query string of the generated URL because even though you mean to write two hashes, you really only specified one. So you need to tell Ruby which is which by delimiting the first hash (or both) with curly brackets. This will generate the HTML you expect:</p><div class="code_container">
314
+ <pre class="brush: ruby; gutter: false; toolbar: false">
315
+ form_tag({controller: "people", action: "search"}, method: "get", class: "nifty_form")
316
+ # =&gt; '&lt;form accept-charset="UTF-8" action="/people/search" method="get" class="nifty_form"&gt;'
317
+
318
+ </pre>
319
+ </div>
320
+ <h4 id="helpers-for-generating-form-elements">1.3 Helpers for Generating Form Elements</h4><p>Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "<em>tag" (such as <code>text_field_tag</code> and <code>check_box_tag</code>), generate just a single <code>&lt;input&gt;</code> element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the <code>params</code> hash in the controller with the value entered by the user for that field. For example, if the form contains `&lt;%= text</em>field_tag(:query) %&gt;<code>, then you would be able to get the value of this field in the controller with</code>params[:query]`.</p><p>When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in <code>params</code>. You can read more about them in <a href="#understanding-parameter-naming-conventions">chapter 7 of this guide</a>. For details on the precise usage of these helpers, please refer to the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html">API documentation</a>.</p><h5 id="checkboxes">1.3.1 Checkboxes</h5><p>Checkboxes are form controls that give the user a set of options they can enable or disable:</p><div class="code_container">
321
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
322
+ &lt;%= check_box_tag(:pet_dog) %&gt;
323
+ &lt;%= label_tag(:pet_dog, "I own a dog") %&gt;
324
+ &lt;%= check_box_tag(:pet_cat) %&gt;
325
+ &lt;%= label_tag(:pet_cat, "I own a cat") %&gt;
326
+
327
+ </pre>
328
+ </div>
329
+ <p>This generates the following:</p><div class="code_container">
330
+ <pre class="brush: xml; gutter: false; toolbar: false">
331
+ &lt;input id="pet_dog" name="pet_dog" type="checkbox" value="1" /&gt;
332
+ &lt;label for="pet_dog"&gt;I own a dog&lt;/label&gt;
333
+ &lt;input id="pet_cat" name="pet_cat" type="checkbox" value="1" /&gt;
334
+ &lt;label for="pet_cat"&gt;I own a cat&lt;/label&gt;
335
+
336
+ </pre>
337
+ </div>
338
+ <p>The first parameter to <code>check_box_tag</code>, of course, is the name of the input. The second parameter, naturally, is the value of the input. This value will be included in the form data (and be present in <code>params</code>) when the checkbox is checked.</p><h5 id="radio-buttons">1.3.2 Radio Buttons</h5><p>Radio buttons, while similar to checkboxes, are controls that specify a set of options in which they are mutually exclusive (i.e., the user can only pick one):</p><div class="code_container">
339
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
340
+ &lt;%= radio_button_tag(:age, "child") %&gt;
341
+ &lt;%= label_tag(:age_child, "I am younger than 21") %&gt;
342
+ &lt;%= radio_button_tag(:age, "adult") %&gt;
343
+ &lt;%= label_tag(:age_adult, "I'm over 21") %&gt;
344
+
345
+ </pre>
346
+ </div>
347
+ <p>Output:</p><div class="code_container">
348
+ <pre class="brush: xml; gutter: false; toolbar: false">
349
+ &lt;input id="age_child" name="age" type="radio" value="child" /&gt;
350
+ &lt;label for="age_child"&gt;I am younger than 21&lt;/label&gt;
351
+ &lt;input id="age_adult" name="age" type="radio" value="adult" /&gt;
352
+ &lt;label for="age_adult"&gt;I'm over 21&lt;/label&gt;
353
+
354
+ </pre>
355
+ </div>
356
+ <p>As with <code>check_box_tag</code>, the second parameter to <code>radio_button_tag</code> is the value of the input. Because these two radio buttons share the same name (<code>age</code>), the user will only be able to select one of them, and <code>params[:age]</code> will contain either <code>"child"</code> or <code>"adult"</code>.</p><div class="note"><p>Always use labels for checkbox and radio buttons. They associate text with a specific option and,
357
+ by expanding the clickable region,
358
+ make it easier for users to click the inputs.</p></div><h4 id="other-helpers-of-interest">1.4 Other Helpers of Interest</h4><p>Other form controls worth mentioning are textareas, password fields,
359
+ hidden fields, search fields, telephone fields, date fields, time fields,
360
+ color fields, datetime fields, datetime-local fields, month fields, week fields,
361
+ URL fields, email fields, number fields and range fields:</p><div class="code_container">
362
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
363
+ &lt;%= text_area_tag(:message, "Hi, nice site", size: "24x6") %&gt;
364
+ &lt;%= password_field_tag(:password) %&gt;
365
+ &lt;%= hidden_field_tag(:parent_id, "5") %&gt;
366
+ &lt;%= search_field(:user, :name) %&gt;
367
+ &lt;%= telephone_field(:user, :phone) %&gt;
368
+ &lt;%= date_field(:user, :born_on) %&gt;
369
+ &lt;%= datetime_field(:user, :meeting_time) %&gt;
370
+ &lt;%= datetime_local_field(:user, :graduation_day) %&gt;
371
+ &lt;%= month_field(:user, :birthday_month) %&gt;
372
+ &lt;%= week_field(:user, :birthday_week) %&gt;
373
+ &lt;%= url_field(:user, :homepage) %&gt;
374
+ &lt;%= email_field(:user, :address) %&gt;
375
+ &lt;%= color_field(:user, :favorite_color) %&gt;
376
+ &lt;%= time_field(:task, :started_at) %&gt;
377
+ &lt;%= number_field(:product, :price, in: 1.0..20.0, step: 0.5) %&gt;
378
+ &lt;%= range_field(:product, :discount, in: 1..100) %&gt;
379
+
380
+ </pre>
381
+ </div>
382
+ <p>Output:</p><div class="code_container">
383
+ <pre class="brush: xml; gutter: false; toolbar: false">
384
+ &lt;textarea id="message" name="message" cols="24" rows="6"&gt;Hi, nice site&lt;/textarea&gt;
385
+ &lt;input id="password" name="password" type="password" /&gt;
386
+ &lt;input id="parent_id" name="parent_id" type="hidden" value="5" /&gt;
387
+ &lt;input id="user_name" name="user[name]" type="search" /&gt;
388
+ &lt;input id="user_phone" name="user[phone]" type="tel" /&gt;
389
+ &lt;input id="user_born_on" name="user[born_on]" type="date" /&gt;
390
+ &lt;input id="user_meeting_time" name="user[meeting_time]" type="datetime" /&gt;
391
+ &lt;input id="user_graduation_day" name="user[graduation_day]" type="datetime-local" /&gt;
392
+ &lt;input id="user_birthday_month" name="user[birthday_month]" type="month" /&gt;
393
+ &lt;input id="user_birthday_week" name="user[birthday_week]" type="week" /&gt;
394
+ &lt;input id="user_homepage" name="user[homepage]" type="url" /&gt;
395
+ &lt;input id="user_address" name="user[address]" type="email" /&gt;
396
+ &lt;input id="user_favorite_color" name="user[favorite_color]" type="color" value="#000000" /&gt;
397
+ &lt;input id="task_started_at" name="task[started_at]" type="time" /&gt;
398
+ &lt;input id="product_price" max="20.0" min="1.0" name="product[price]" step="0.5" type="number" /&gt;
399
+ &lt;input id="product_discount" max="100" min="1" name="product[discount]" type="range" /&gt;
400
+
401
+ </pre>
402
+ </div>
403
+ <p>Hidden inputs are not shown to the user but instead hold data like any textual input. Values inside them can be changed with JavaScript.</p><div class="warning"><p>The search, telephone, date, time, color, datetime, datetime-local,
404
+ month, week, URL, email, number and range inputs are HTML5 controls.
405
+ If you require your app to have a consistent experience in older browsers,
406
+ you will need an HTML5 polyfill (provided by CSS and/or JavaScript).
407
+ There is definitely <a href="https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills">no shortage of solutions for this</a>, although a couple of popular tools at the moment are
408
+ <a href="http://www.modernizr.com/">Modernizr</a> and <a href="http://yepnopejs.com/">yepnope</a>,
409
+ which provide a simple way to add functionality based on the presence of
410
+ detected HTML5 features.</p></div><div class="info"><p>If you're using password input fields (for any purpose), you might want to configure your application to prevent those parameters from being logged. You can learn about this in the <a href="security.html#logging">Security Guide</a>.</p></div><h3 id="dealing-with-model-objects">2 Dealing with Model Objects</h3><h4 id="dealing-with-model-objects-model-object-helpers">2.1 Model Object Helpers</h4><p>A particularly common task for a form is editing or creating a model object. While the <code>*_tag</code> helpers can certainly be used for this task they are somewhat verbose as for each tag you would have to ensure the correct parameter name is used and set the default value of the input appropriately. Rails provides helpers tailored to this task. These helpers lack the <code>_tag</code> suffix, for example <code>text_field</code>, <code>text_area</code>.</p><p>For these helpers the first argument is the name of an instance variable and the second is the name of a method (usually an attribute) to call on that object. Rails will set the value of the input control to the return value of that method for the object and set an appropriate input name. If your controller has defined <code>@person</code> and that person's name is Henry then a form containing:</p><div class="code_container">
411
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
412
+ &lt;%= text_field(:person, :name) %&gt;
413
+
414
+ </pre>
415
+ </div>
416
+ <p>will produce output similar to</p><div class="code_container">
417
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
418
+ &lt;input id="person_name" name="person[name]" type="text" value="Henry"/&gt;
419
+
420
+ </pre>
421
+ </div>
422
+ <p>Upon form submission the value entered by the user will be stored in <code>params[:person][:name]</code>. The <code>params[:person]</code> hash is suitable for passing to <code>Person.new</code> or, if <code>@person</code> is an instance of Person, <code>@person.update</code>. While the name of an attribute is the most common second parameter to these helpers this is not compulsory. In the example above, as long as person objects have a <code>name</code> and a <code>name=</code> method Rails will be happy.</p><div class="warning"><p>You must pass the name of an instance variable, i.e. <code>:person</code> or <code>"person"</code>, not an actual instance of your model object.</p></div><p>Rails provides helpers for displaying the validation errors associated with a model object. These are covered in detail by the <a href="./active_record_validations.html#displaying-validation-errors-in-views">Active Record Validations</a> guide.</p><h4 id="binding-a-form-to-an-object">2.2 Binding a Form to an Object</h4><p>While this is an increase in comfort it is far from perfect. If <code>Person</code> has many attributes to edit then we would be repeating the name of the edited object many times. What we want to do is somehow bind a form to a model object, which is exactly what <code>form_for</code> does.</p><p>Assume we have a controller for dealing with articles <code>app/controllers/articles_controller.rb</code>:</p><div class="code_container">
423
+ <pre class="brush: ruby; gutter: false; toolbar: false">
424
+ def new
425
+ @article = Article.new
426
+ end
427
+
428
+ </pre>
429
+ </div>
430
+ <p>The corresponding view <code>app/views/articles/new.html.erb</code> using <code>form_for</code> looks like this:</p><div class="code_container">
431
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
432
+ &lt;%= form_for @article, url: {action: "create"}, html: {class: "nifty_form"} do |f| %&gt;
433
+ &lt;%= f.text_field :title %&gt;
434
+ &lt;%= f.text_area :body, size: "60x12" %&gt;
435
+ &lt;%= f.submit "Create" %&gt;
436
+ &lt;% end %&gt;
437
+
438
+ </pre>
439
+ </div>
440
+ <p>There are a few things to note here:</p>
441
+ <ul>
442
+ <li>
443
+ <code>@article</code> is the actual object being edited.</li>
444
+ <li>There is a single hash of options. Routing options are passed in the <code>:url</code> hash, HTML options are passed in the <code>:html</code> hash. Also you can provide a <code>:namespace</code> option for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generated HTML id.</li>
445
+ <li>The <code>form_for</code> method yields a <strong>form builder</strong> object (the <code>f</code> variable).</li>
446
+ <li>Methods to create form controls are called <strong>on</strong> the form builder object <code>f</code>.</li>
447
+ </ul>
448
+ <p>The resulting HTML is:</p><div class="code_container">
449
+ <pre class="brush: xml; gutter: false; toolbar: false">
450
+ &lt;form accept-charset="UTF-8" action="/articles/create" method="post" class="nifty_form"&gt;
451
+ &lt;input id="article_title" name="article[title]" type="text" /&gt;
452
+ &lt;textarea id="article_body" name="article[body]" cols="60" rows="12"&gt;&lt;/textarea&gt;
453
+ &lt;input name="commit" type="submit" value="Create" /&gt;
454
+ &lt;/form&gt;
455
+
456
+ </pre>
457
+ </div>
458
+ <p>The name passed to <code>form_for</code> controls the key used in <code>params</code> to access the form's values. Here the name is <code>article</code> and so all the inputs have names of the form <code>article[attribute_name]</code>. Accordingly, in the <code>create</code> action <code>params[:article]</code> will be a hash with keys <code>:title</code> and <code>:body</code>. You can read more about the significance of input names in the parameter_names section.</p><p>The helper methods called on the form builder are identical to the model object helpers except that it is not necessary to specify which object is being edited since this is already managed by the form builder.</p><p>You can create a similar binding without actually creating <code>&lt;form&gt;</code> tags with the <code>fields_for</code> helper. This is useful for editing additional model objects with the same form. For example if you had a <code>Person</code> model with an associated <code>ContactDetail</code> model you could create a form for creating both like so:</p><div class="code_container">
459
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
460
+ &lt;%= form_for @person, url: {action: "create"} do |person_form| %&gt;
461
+ &lt;%= person_form.text_field :name %&gt;
462
+ &lt;%= fields_for @person.contact_detail do |contact_details_form| %&gt;
463
+ &lt;%= contact_details_form.text_field :phone_number %&gt;
464
+ &lt;% end %&gt;
465
+ &lt;% end %&gt;
466
+
467
+ </pre>
468
+ </div>
469
+ <p>which produces the following output:</p><div class="code_container">
470
+ <pre class="brush: xml; gutter: false; toolbar: false">
471
+ &lt;form accept-charset="UTF-8" action="/people/create" class="new_person" id="new_person" method="post"&gt;
472
+ &lt;input id="person_name" name="person[name]" type="text" /&gt;
473
+ &lt;input id="contact_detail_phone_number" name="contact_detail[phone_number]" type="text" /&gt;
474
+ &lt;/form&gt;
475
+
476
+ </pre>
477
+ </div>
478
+ <p>The object yielded by <code>fields_for</code> is a form builder like the one yielded by <code>form_for</code> (in fact <code>form_for</code> calls <code>fields_for</code> internally).</p><h4 id="relying-on-record-identification">2.3 Relying on Record Identification</h4><p>The Article model is directly available to users of the application, so - following the best practices for developing with Rails - you should declare it <strong>a resource</strong>:</p><div class="code_container">
479
+ <pre class="brush: ruby; gutter: false; toolbar: false">
480
+ resources :articles
481
+
482
+ </pre>
483
+ </div>
484
+ <div class="info"><p>Declaring a resource has a number of side-affects. See <a href="routing.html#resource-routing-the-rails-default">Rails Routing From the Outside In</a> for more information on setting up and using resources.</p></div><p>When dealing with RESTful resources, calls to <code>form_for</code> can get significantly easier if you rely on <strong>record identification</strong>. In short, you can just pass the model instance and have Rails figure out model name and the rest:</p><div class="code_container">
485
+ <pre class="brush: ruby; gutter: false; toolbar: false">
486
+ ## Creating a new article
487
+ # long-style:
488
+ form_for(@article, url: articles_path)
489
+ # same thing, short-style (record identification gets used):
490
+ form_for(@article)
491
+
492
+ ## Editing an existing article
493
+ # long-style:
494
+ form_for(@article, url: article_path(@article), html: {method: "patch"})
495
+ # short-style:
496
+ form_for(@article)
497
+
498
+ </pre>
499
+ </div>
500
+ <p>Notice how the short-style <code>form_for</code> invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking <code>record.new_record?</code>. It also selects the correct path to submit to and the name based on the class of the object.</p><p>Rails will also automatically set the <code>class</code> and <code>id</code> of the form appropriately: a form creating an article would have <code>id</code> and <code>class</code> <code>new_article</code>. If you were editing the article with id 23, the <code>class</code> would be set to <code>edit_article</code> and the id to <code>edit_article_23</code>. These attributes will be omitted for brevity in the rest of this guide.</p><div class="warning"><p>When you're using STI (single-table inheritance) with your models, you can't rely on record identification on a subclass if only their parent class is declared a resource. You will have to specify the model name, <code>:url</code>, and <code>:method</code> explicitly.</p></div><h5 id="dealing-with-namespaces">2.3.1 Dealing with Namespaces</h5><p>If you have created namespaced routes, <code>form_for</code> has a nifty shorthand for that too. If your application has an admin namespace then</p><div class="code_container">
501
+ <pre class="brush: ruby; gutter: false; toolbar: false">
502
+ form_for [:admin, @article]
503
+
504
+ </pre>
505
+ </div>
506
+ <p>will create a form that submits to the <code>ArticlesController</code> inside the admin namespace (submitting to <code>admin_article_path(@article)</code> in the case of an update). If you have several levels of namespacing then the syntax is similar:</p><div class="code_container">
507
+ <pre class="brush: ruby; gutter: false; toolbar: false">
508
+ form_for [:admin, :management, @article]
509
+
510
+ </pre>
511
+ </div>
512
+ <p>For more information on Rails' routing system and the associated conventions, please see the <a href="routing.html">routing guide</a>.</p><h4 id="how-do-forms-with-patch,-put,-or-delete-methods-work-questionmark">2.4 How do forms with PATCH, PUT, or DELETE methods work?</h4><p>The Rails framework encourages RESTful design of your applications, which means you'll be making a lot of "PATCH" and "DELETE" requests (besides "GET" and "POST"). However, most browsers <em>don't support</em> methods other than "GET" and "POST" when it comes to submitting forms.</p><p>Rails works around this issue by emulating other methods over POST with a hidden input named <code>"_method"</code>, which is set to reflect the desired method:</p><div class="code_container">
513
+ <pre class="brush: ruby; gutter: false; toolbar: false">
514
+ form_tag(search_path, method: "patch")
515
+
516
+ </pre>
517
+ </div>
518
+ <p>output:</p><div class="code_container">
519
+ <pre class="brush: xml; gutter: false; toolbar: false">
520
+ &lt;form accept-charset="UTF-8" action="/search" method="post"&gt;
521
+ &lt;input name="_method" type="hidden" value="patch" /&gt;
522
+ &lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;
523
+ &lt;input name="authenticity_token" type="hidden" value="f755bb0ed134b76c432144748a6d4b7a7ddf2b71" /&gt;
524
+ ...
525
+ &lt;/form&gt;
526
+
527
+ </pre>
528
+ </div>
529
+ <p>When parsing POSTed data, Rails will take into account the special <code>_method</code> parameter and acts as if the HTTP method was the one specified inside it ("PATCH" in this example).</p><h3 id="making-select-boxes-with-ease">3 Making Select Boxes with Ease</h3><p>Select boxes in HTML require a significant amount of markup (one <code>OPTION</code> element for each option to choose from), therefore it makes the most sense for them to be dynamically generated.</p><p>Here is what the markup might look like:</p><div class="code_container">
530
+ <pre class="brush: xml; gutter: false; toolbar: false">
531
+ &lt;select name="city_id" id="city_id"&gt;
532
+ &lt;option value="1"&gt;Lisbon&lt;/option&gt;
533
+ &lt;option value="2"&gt;Madrid&lt;/option&gt;
534
+ ...
535
+ &lt;option value="12"&gt;Berlin&lt;/option&gt;
536
+ &lt;/select&gt;
537
+
538
+ </pre>
539
+ </div>
540
+ <p>Here you have a list of cities whose names are presented to the user. Internally the application only wants to handle their IDs so they are used as the options' value attribute. Let's see how Rails can help out here.</p><h4 id="the-select-and-option-tags">3.1 The Select and Option Tags</h4><p>The most generic helper is <code>select_tag</code>, which - as the name implies - simply generates the <code>SELECT</code> tag that encapsulates an options string:</p><div class="code_container">
541
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
542
+ &lt;%= select_tag(:city_id, '&lt;option value="1"&gt;Lisbon&lt;/option&gt;...') %&gt;
543
+
544
+ </pre>
545
+ </div>
546
+ <p>This is a start, but it doesn't dynamically create the option tags. You can generate option tags with the <code>options_for_select</code> helper:</p><div class="code_container">
547
+ <pre class="brush: plain; gutter: false; toolbar: false">
548
+ &lt;%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...]) %&gt;
549
+
550
+ output:
551
+
552
+ &lt;option value="1"&gt;Lisbon&lt;/option&gt;
553
+ &lt;option value="2"&gt;Madrid&lt;/option&gt;
554
+ ...
555
+
556
+ </pre>
557
+ </div>
558
+ <p>The first argument to <code>options_for_select</code> is a nested array where each element has two elements: option text (city name) and option value (city id). The option value is what will be submitted to your controller. Often this will be the id of a corresponding database object but this does not have to be the case.</p><p>Knowing this, you can combine <code>select_tag</code> and <code>options_for_select</code> to achieve the desired, complete markup:</p><div class="code_container">
559
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
560
+ &lt;%= select_tag(:city_id, options_for_select(...)) %&gt;
561
+
562
+ </pre>
563
+ </div>
564
+ <p><code>options_for_select</code> allows you to pre-select an option by passing its value.</p><div class="code_container">
565
+ <pre class="brush: plain; gutter: false; toolbar: false">
566
+ &lt;%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %&gt;
567
+
568
+ output:
569
+
570
+ &lt;option value="1"&gt;Lisbon&lt;/option&gt;
571
+ &lt;option value="2" selected="selected"&gt;Madrid&lt;/option&gt;
572
+ ...
573
+
574
+ </pre>
575
+ </div>
576
+ <p>Whenever Rails sees that the internal value of an option being generated matches this value, it will add the <code>selected</code> attribute to that option.</p><div class="info"><p>The second argument to <code>options_for_select</code> must be exactly equal to the desired internal value. In particular if the value is the integer <code>2</code> you cannot pass <code>"2"</code> to <code>options_for_select</code> - you must pass <code>2</code>. Be aware of values extracted from the <code>params</code> hash as they are all strings.</p></div><div class="warning"><p>when <code>:include_blank</code> or <code>:prompt</code> are not present, <code>:include_blank</code> is forced true if the select attribute <code>required</code> is true, display <code>size</code> is one and <code>multiple</code> is not true.</p></div><p>You can add arbitrary attributes to the options using hashes:</p><div class="code_container">
577
+ <pre class="brush: plain; gutter: false; toolbar: false">
578
+ &lt;%= options_for_select(
579
+ [
580
+ ['Lisbon', 1, { 'data-size' =&gt; '2.8 million' }],
581
+ ['Madrid', 2, { 'data-size' =&gt; '3.2 million' }]
582
+ ], 2
583
+ ) %&gt;
584
+
585
+ output:
586
+
587
+ &lt;option value="1" data-size="2.8 million"&gt;Lisbon&lt;/option&gt;
588
+ &lt;option value="2" selected="selected" data-size="3.2 million"&gt;Madrid&lt;/option&gt;
589
+ ...
590
+
591
+ </pre>
592
+ </div>
593
+ <h4 id="select-boxes-for-dealing-with-models">3.2 Select Boxes for Dealing with Models</h4><p>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 <code>_tag</code> suffix from <code>select_tag</code>:</p><div class="code_container">
594
+ <pre class="brush: ruby; gutter: false; toolbar: false">
595
+ # controller:
596
+ @person = Person.new(city_id: 2)
597
+
598
+ </pre>
599
+ </div>
600
+ <div class="code_container">
601
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
602
+ # view:
603
+ &lt;%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %&gt;
604
+
605
+ </pre>
606
+ </div>
607
+ <p>Notice that the third parameter, the options array, is the same kind of argument you pass to <code>options_for_select</code>. One advantage here is that you don't have to worry about pre-selecting the correct city if the user already has one - Rails will do this for you by reading from the <code>@person.city_id</code> attribute.</p><p>As with other helpers, if you were to use the <code>select</code> helper on a form builder scoped to the <code>@person</code> object, the syntax would be:</p><div class="code_container">
608
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
609
+ # select on a form builder
610
+ &lt;%= f.select(:city_id, ...) %&gt;
611
+
612
+ </pre>
613
+ </div>
614
+ <p>You can also pass a block to <code>select</code> helper:</p><div class="code_container">
615
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
616
+ &lt;%= f.select(:city_id) do %&gt;
617
+ &lt;% [['Lisbon', 1], ['Madrid', 2]].each do |c| -%&gt;
618
+ &lt;%= content_tag(:option, c.first, value: c.last) %&gt;
619
+ &lt;% end %&gt;
620
+ &lt;% end %&gt;
621
+
622
+ </pre>
623
+ </div>
624
+ <div class="warning"><p>If you are using <code>select</code> (or similar helpers such as <code>collection_select</code>, <code>select_tag</code>) to set a <code>belongs_to</code> association you must pass the name of the foreign key (in the example above <code>city_id</code>), not the name of association itself. If you specify <code>city</code> instead of <code>city_id</code> Active Record will raise an error along the lines of <code>ActiveRecord::AssociationTypeMismatch: City(#17815740) expected, got String(#1138750)</code> when you pass the <code>params</code> hash to <code>Person.new</code> or <code>update</code>. Another way of looking at this is that form helpers only edit attributes. You should also be aware of the potential security ramifications of allowing users to edit foreign keys directly.</p></div><h4 id="option-tags-from-a-collection-of-arbitrary-objects">3.3 Option Tags from a Collection of Arbitrary Objects</h4><p>Generating options tags with <code>options_for_select</code> requires that you create an array containing the text and value for each option. But what if you had a <code>City</code> model (perhaps an Active Record one) and you wanted to generate option tags from a collection of those objects? One solution would be to make a nested array by iterating over them:</p><div class="code_container">
625
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
626
+ &lt;% cities_array = City.all.map { |city| [city.name, city.id] } %&gt;
627
+ &lt;%= options_for_select(cities_array) %&gt;
628
+
629
+ </pre>
630
+ </div>
631
+ <p>This is a perfectly valid solution, but Rails provides a less verbose alternative: <code>options_from_collection_for_select</code>. This helper expects a collection of arbitrary objects and two additional arguments: the names of the methods to read the option <strong>value</strong> and <strong>text</strong> from, respectively:</p><div class="code_container">
632
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
633
+ &lt;%= options_from_collection_for_select(City.all, :id, :name) %&gt;
634
+
635
+ </pre>
636
+ </div>
637
+ <p>As the name implies, this only generates option tags. To generate a working select box you would need to use it in conjunction with <code>select_tag</code>, just as you would with <code>options_for_select</code>. When working with model objects, just as <code>select</code> combines <code>select_tag</code> and <code>options_for_select</code>, <code>collection_select</code> combines <code>select_tag</code> with <code>options_from_collection_for_select</code>.</p><div class="code_container">
638
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
639
+ &lt;%= collection_select(:person, :city_id, City.all, :id, :name) %&gt;
640
+
641
+ </pre>
642
+ </div>
643
+ <p>To recap, <code>options_from_collection_for_select</code> is to <code>collection_select</code> what <code>options_for_select</code> is to <code>select</code>.</p><div class="note"><p>Pairs passed to <code>options_for_select</code> should have the name first and the id second, however with <code>options_from_collection_for_select</code> the first argument is the value method and the second the text method.</p></div><h4 id="time-zone-and-country-select">3.4 Time Zone and Country Select</h4><p>To leverage time zone support in Rails, you have to ask your users what time zone they are in. Doing so would require generating select options from a list of pre-defined TimeZone objects using <code>collection_select</code>, but you can simply use the <code>time_zone_select</code> helper that already wraps this:</p><div class="code_container">
644
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
645
+ &lt;%= time_zone_select(:person, :time_zone) %&gt;
646
+
647
+ </pre>
648
+ </div>
649
+ <p>There is also <code>time_zone_options_for_select</code> helper for a more manual (therefore more customizable) way of doing this. Read the API documentation to learn about the possible arguments for these two methods.</p><p>Rails <em>used</em> to have a <code>country_select</code> helper for choosing countries, but this has been extracted to the <a href="https://github.com/stefanpenner/country_select">country_select plugin</a>. When using this, be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from Rails).</p><h3 id="using-date-and-time-form-helpers">4 Using Date and Time Form Helpers</h3><p>You can choose not to use the form helpers generating HTML5 date and time input fields and use the alternative date and time helpers. These date and time helpers differ from all the other form helpers in two important respects:</p>
650
+ <ul>
651
+ <li>Dates and times are not representable by a single input element. Instead you have several, one for each component (year, month, day etc.) and so there is no single value in your <code>params</code> hash with your date or time.</li>
652
+ <li>Other helpers use the <code>_tag</code> suffix to indicate whether a helper is a barebones helper or one that operates on model objects. With dates and times, <code>select_date</code>, <code>select_time</code> and <code>select_datetime</code> are the barebones helpers, <code>date_select</code>, <code>time_select</code> and <code>datetime_select</code> are the equivalent model object helpers.</li>
653
+ </ul>
654
+ <p>Both of these families of helpers will create a series of select boxes for the different components (year, month, day etc.).</p><h4 id="barebones-helpers">4.1 Barebones Helpers</h4><p>The <code>select_*</code> family of helpers take as their first argument an instance of <code>Date</code>, <code>Time</code> or <code>DateTime</code> that is used as the currently selected value. You may omit this parameter, in which case the current date is used. For example</p><div class="code_container">
655
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
656
+ &lt;%= select_date Date.today, prefix: :start_date %&gt;
657
+
658
+ </pre>
659
+ </div>
660
+ <p>outputs (with actual option values omitted for brevity)</p><div class="code_container">
661
+ <pre class="brush: xml; gutter: false; toolbar: false">
662
+ &lt;select id="start_date_year" name="start_date[year]"&gt; ... &lt;/select&gt;
663
+ &lt;select id="start_date_month" name="start_date[month]"&gt; ... &lt;/select&gt;
664
+ &lt;select id="start_date_day" name="start_date[day]"&gt; ... &lt;/select&gt;
665
+
666
+ </pre>
667
+ </div>
668
+ <p>The above inputs would result in <code>params[:start_date]</code> being a hash with keys <code>:year</code>, <code>:month</code>, <code>:day</code>. To get an actual <code>Date</code>, <code>Time</code> or <code>DateTime</code> object you would have to extract these values and pass them to the appropriate constructor, for example</p><div class="code_container">
669
+ <pre class="brush: ruby; gutter: false; toolbar: false">
670
+ Date.civil(params[:start_date][:year].to_i, params[:start_date][:month].to_i, params[:start_date][:day].to_i)
671
+
672
+ </pre>
673
+ </div>
674
+ <p>The <code>:prefix</code> option is the key used to retrieve the hash of date components from the <code>params</code> hash. Here it was set to <code>start_date</code>, if omitted it will default to <code>date</code>.</p><h4 id="using-date-and-time-form-helpers-model-object-helpers">4.2 Model Object Helpers</h4><p><code>select_date</code> does not work well with forms that update or create Active Record objects as Active Record expects each element of the <code>params</code> hash to correspond to one attribute.
675
+ The model object helpers for dates and times submit parameters with special names; when Active Record sees parameters with such names it knows they must be combined with the other parameters and given to a constructor appropriate to the column type. For example:</p><div class="code_container">
676
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
677
+ &lt;%= date_select :person, :birth_date %&gt;
678
+
679
+ </pre>
680
+ </div>
681
+ <p>outputs (with actual option values omitted for brevity)</p><div class="code_container">
682
+ <pre class="brush: xml; gutter: false; toolbar: false">
683
+ &lt;select id="person_birth_date_1i" name="person[birth_date(1i)]"&gt; ... &lt;/select&gt;
684
+ &lt;select id="person_birth_date_2i" name="person[birth_date(2i)]"&gt; ... &lt;/select&gt;
685
+ &lt;select id="person_birth_date_3i" name="person[birth_date(3i)]"&gt; ... &lt;/select&gt;
686
+
687
+ </pre>
688
+ </div>
689
+ <p>which results in a <code>params</code> hash like</p><div class="code_container">
690
+ <pre class="brush: ruby; gutter: false; toolbar: false">
691
+ {'person' =&gt; {'birth_date(1i)' =&gt; '2008', 'birth_date(2i)' =&gt; '11', 'birth_date(3i)' =&gt; '22'}}
692
+
693
+ </pre>
694
+ </div>
695
+ <p>When this is passed to <code>Person.new</code> (or <code>update</code>), Active Record spots that these parameters should all be used to construct the <code>birth_date</code> attribute and uses the suffixed information to determine in which order it should pass these parameters to functions such as <code>Date.civil</code>.</p><h4 id="common-options">4.3 Common Options</h4><p>Both families of helpers use the same core set of functions to generate the individual select tags and so both accept largely the same options. In particular, by default Rails will generate year options 5 years either side of the current year. If this is not an appropriate range, the <code>:start_year</code> and <code>:end_year</code> options override this. For an exhaustive list of the available options, refer to the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html">API documentation</a>.</p><p>As a rule of thumb you should be using <code>date_select</code> when working with model objects and <code>select_date</code> in other cases, such as a search form which filters results by date.</p><div class="note"><p>In many cases the built-in date pickers are clumsy as they do not aid the user in working out the relationship between the date and the day of the week.</p></div><h4 id="individual-components">4.4 Individual Components</h4><p>Occasionally you need to display just a single date component such as a year or a month. Rails provides a series of helpers for this, one for each component <code>select_year</code>, <code>select_month</code>, <code>select_day</code>, <code>select_hour</code>, <code>select_minute</code>, <code>select_second</code>. These helpers are fairly straightforward. By default they will generate an input field named after the time component (for example "year" for <code>select_year</code>, "month" for <code>select_month</code> etc.) although this can be overridden with the <code>:field_name</code> option. The <code>:prefix</code> option works in the same way that it does for <code>select_date</code> and <code>select_time</code> and has the same default value.</p><p>The first parameter specifies which value should be selected and can either be an instance of a <code>Date</code>, <code>Time</code> or <code>DateTime</code>, in which case the relevant component will be extracted, or a numerical value. For example</p><div class="code_container">
696
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
697
+ &lt;%= select_year(2009) %&gt;
698
+ &lt;%= select_year(Time.now) %&gt;
699
+
700
+ </pre>
701
+ </div>
702
+ <p>will produce the same output if the current year is 2009 and the value chosen by the user can be retrieved by <code>params[:date][:year]</code>.</p><h3 id="uploading-files">5 Uploading Files</h3><p>A common task is uploading some sort of file, whether it's a picture of a person or a CSV file containing data to process. The most important thing to remember with file uploads is that the rendered form's encoding <strong>MUST</strong> be set to "multipart/form-data". If you use <code>form_for</code>, this is done automatically. If you use <code>form_tag</code>, you must set it yourself, as per the following example.</p><p>The following two forms both upload a file.</p><div class="code_container">
703
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
704
+ &lt;%= form_tag({action: :upload}, multipart: true) do %&gt;
705
+ &lt;%= file_field_tag 'picture' %&gt;
706
+ &lt;% end %&gt;
707
+
708
+ &lt;%= form_for @person do |f| %&gt;
709
+ &lt;%= f.file_field :picture %&gt;
710
+ &lt;% end %&gt;
711
+
712
+ </pre>
713
+ </div>
714
+ <p>Rails provides the usual pair of helpers: the barebones <code>file_field_tag</code> and the model oriented <code>file_field</code>. The only difference with other helpers is that you cannot set a default value for file inputs as this would have no meaning. As you would expect in the first case the uploaded file is in <code>params[:picture]</code> and in the second case in <code>params[:person][:picture]</code>.</p><h4 id="what-gets-uploaded">5.1 What Gets Uploaded</h4><p>The object in the <code>params</code> hash is an instance of a subclass of <code>IO</code>. Depending on the size of the uploaded file it may in fact be a StringIO or an instance of <code>File</code> backed by a temporary file. In both cases the object will have an <code>original_filename</code> attribute containing the name the file had on the user's computer and a <code>content_type</code> attribute containing the MIME type of the uploaded file. The following snippet saves the uploaded content in <code>#{Rails.root}/public/uploads</code> under the same name as the original file (assuming the form was the one in the previous example).</p><div class="code_container">
715
+ <pre class="brush: ruby; gutter: false; toolbar: false">
716
+ def upload
717
+ uploaded_io = params[:person][:picture]
718
+ File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file|
719
+ file.write(uploaded_io.read)
720
+ end
721
+ end
722
+
723
+ </pre>
724
+ </div>
725
+ <p>Once a file has been uploaded, there are a multitude of potential tasks, ranging from where to store the files (on disk, Amazon S3, etc) and associating them with models to resizing image files and generating thumbnails. The intricacies of this are beyond the scope of this guide, but there are several libraries designed to assist with these. Two of the better known ones are <a href="https://github.com/jnicklas/carrierwave">CarrierWave</a> and <a href="https://github.com/thoughtbot/paperclip">Paperclip</a>.</p><div class="note"><p>If the user has not selected a file the corresponding parameter will be an empty string.</p></div><h4 id="dealing-with-ajax">5.2 Dealing with Ajax</h4><p>Unlike other forms making an asynchronous file upload form is not as simple as providing <code>form_for</code> with <code>remote: true</code>. With an Ajax form the serialization is done by JavaScript running inside the browser and since JavaScript cannot read files from your hard drive the file cannot be uploaded. The most common workaround is to use an invisible iframe that serves as the target for the form submission.</p><h3 id="customizing-form-builders">6 Customizing Form Builders</h3><p>As mentioned previously the object yielded by <code>form_for</code> and <code>fields_for</code> is an instance of <code>FormBuilder</code> (or a subclass thereof). Form builders encapsulate the notion of displaying form elements for a single object. While you can of course write helpers for your forms in the usual way, you can also subclass <code>FormBuilder</code> and add the helpers there. For example</p><div class="code_container">
726
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
727
+ &lt;%= form_for @person do |f| %&gt;
728
+ &lt;%= text_field_with_label f, :first_name %&gt;
729
+ &lt;% end %&gt;
730
+
731
+ </pre>
732
+ </div>
733
+ <p>can be replaced with</p><div class="code_container">
734
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
735
+ &lt;%= form_for @person, builder: LabellingFormBuilder do |f| %&gt;
736
+ &lt;%= f.text_field :first_name %&gt;
737
+ &lt;% end %&gt;
738
+
739
+ </pre>
740
+ </div>
741
+ <p>by defining a <code>LabellingFormBuilder</code> class similar to the following:</p><div class="code_container">
742
+ <pre class="brush: ruby; gutter: false; toolbar: false">
743
+ class LabellingFormBuilder &lt; ActionView::Helpers::FormBuilder
744
+ def text_field(attribute, options={})
745
+ label(attribute) + super
746
+ end
747
+ end
748
+
749
+ </pre>
750
+ </div>
751
+ <p>If you reuse this frequently you could define a <code>labeled_form_for</code> helper that automatically applies the <code>builder: LabellingFormBuilder</code> option.</p><p>The form builder used also determines what happens when you do</p><div class="code_container">
752
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
753
+ &lt;%= render partial: f %&gt;
754
+
755
+ </pre>
756
+ </div>
757
+ <p>If <code>f</code> is an instance of <code>FormBuilder</code> then this will render the <code>form</code> partial, setting the partial's object to the form builder. If the form builder is of class <code>LabellingFormBuilder</code> then the <code>labelling_form</code> partial would be rendered instead.</p><h3 id="understanding-parameter-naming-conventions">7 Understanding Parameter Naming Conventions</h3><p>As you've seen in the previous sections, values from forms can be at the top level of the <code>params</code> hash or nested in another hash. For example in a standard <code>create</code>
758
+ action for a Person model, <code>params[:person]</code> would usually be a hash of all the attributes for the person to create. The <code>params</code> hash can also contain arrays, arrays of hashes and so on.</p><p>Fundamentally HTML forms don't know about any sort of structured data, all they generate is name-value pairs, where pairs are just plain strings. The arrays and hashes you see in your application are the result of some parameter naming conventions that Rails uses.</p><div class="info"><p>You may find you can try out examples in this section faster by using the console to directly invoke Racks' parameter parser. For example,</p></div><div class="code_container">
759
+ <pre class="brush: ruby; gutter: false; toolbar: false">
760
+ Rack::Utils.parse_query "name=fred&amp;phone=0123456789"
761
+ # =&gt; {"name"=&gt;"fred", "phone"=&gt;"0123456789"}
762
+
763
+ </pre>
764
+ </div>
765
+ <h4 id="basic-structures">7.1 Basic Structures</h4><p>The two basic structures are arrays and hashes. Hashes mirror the syntax used for accessing the value in <code>params</code>. For example if a form contains</p><div class="code_container">
766
+ <pre class="brush: xml; gutter: false; toolbar: false">
767
+ &lt;input id="person_name" name="person[name]" type="text" value="Henry"/&gt;
768
+
769
+ </pre>
770
+ </div>
771
+ <p>the <code>params</code> hash will contain</p><div class="code_container">
772
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
773
+ {'person' =&gt; {'name' =&gt; 'Henry'}}
774
+
775
+ </pre>
776
+ </div>
777
+ <p>and <code>params[:person][:name]</code> will retrieve the submitted value in the controller.</p><p>Hashes can be nested as many levels as required, for example</p><div class="code_container">
778
+ <pre class="brush: xml; gutter: false; toolbar: false">
779
+ &lt;input id="person_address_city" name="person[address][city]" type="text" value="New York"/&gt;
780
+
781
+ </pre>
782
+ </div>
783
+ <p>will result in the <code>params</code> hash being</p><div class="code_container">
784
+ <pre class="brush: ruby; gutter: false; toolbar: false">
785
+ {'person' =&gt; {'address' =&gt; {'city' =&gt; 'New York'}}}
786
+
787
+ </pre>
788
+ </div>
789
+ <p>Normally Rails ignores duplicate parameter names. If the parameter name contains an empty set of square brackets [] then they will be accumulated in an array. If you wanted people to be able to input multiple phone numbers, you could place this in the form:</p><div class="code_container">
790
+ <pre class="brush: xml; gutter: false; toolbar: false">
791
+ &lt;input name="person[phone_number][]" type="text"/&gt;
792
+ &lt;input name="person[phone_number][]" type="text"/&gt;
793
+ &lt;input name="person[phone_number][]" type="text"/&gt;
794
+
795
+ </pre>
796
+ </div>
797
+ <p>This would result in <code>params[:person][:phone_number]</code> being an array.</p><h4 id="combining-them">7.2 Combining Them</h4><p>We can mix and match these two concepts. For example, one element of a hash might be an array as in the previous example, or you can have an array of hashes. For example a form might let you create any number of addresses by repeating the following form fragment</p><div class="code_container">
798
+ <pre class="brush: xml; gutter: false; toolbar: false">
799
+ &lt;input name="addresses[][line1]" type="text"/&gt;
800
+ &lt;input name="addresses[][line2]" type="text"/&gt;
801
+ &lt;input name="addresses[][city]" type="text"/&gt;
802
+
803
+ </pre>
804
+ </div>
805
+ <p>This would result in <code>params[:addresses]</code> being an array of hashes with keys <code>line1</code>, <code>line2</code> and <code>city</code>. Rails decides to start accumulating values in a new hash whenever it encounters an input name that already exists in the current hash.</p><p>There's a restriction, however, while hashes can be nested arbitrarily, only one level of "arrayness" is allowed. Arrays can be usually replaced by hashes, for example instead of having an array of model objects one can have a hash of model objects keyed by their id, an array index or some other parameter.</p><div class="warning"><p>Array parameters do not play well with the <code>check_box</code> helper. According to the HTML specification unchecked checkboxes submit no value. However it is often convenient for a checkbox to always submit a value. The <code>check_box</code> helper fakes this by creating an auxiliary hidden input with the same name. If the checkbox is unchecked only the hidden input is submitted and if it is checked then both are submitted but the value submitted by the checkbox takes precedence. When working with array parameters this duplicate submission will confuse Rails since duplicate input names are how it decides when to start a new array element. It is preferable to either use <code>check_box_tag</code> or to use hashes instead of arrays.</p></div><h4 id="using-form-helpers">7.3 Using Form Helpers</h4><p>The previous sections did not use the Rails form helpers at all. While you can craft the input names yourself and pass them directly to helpers such as <code>text_field_tag</code> Rails also provides higher level support. The two tools at your disposal here are the name parameter to <code>form_for</code> and <code>fields_for</code> and the <code>:index</code> option that helpers take.</p><p>You might want to render a form with a set of edit fields for each of a person's addresses. For example:</p><div class="code_container">
806
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
807
+ &lt;%= form_for @person do |person_form| %&gt;
808
+ &lt;%= person_form.text_field :name %&gt;
809
+ &lt;% @person.addresses.each do |address| %&gt;
810
+ &lt;%= person_form.fields_for address, index: address.id do |address_form|%&gt;
811
+ &lt;%= address_form.text_field :city %&gt;
812
+ &lt;% end %&gt;
813
+ &lt;% end %&gt;
814
+ &lt;% end %&gt;
815
+
816
+ </pre>
817
+ </div>
818
+ <p>Assuming the person had two addresses, with ids 23 and 45 this would create output similar to this:</p><div class="code_container">
819
+ <pre class="brush: xml; gutter: false; toolbar: false">
820
+ &lt;form accept-charset="UTF-8" action="/people/1" class="edit_person" id="edit_person_1" method="post"&gt;
821
+ &lt;input id="person_name" name="person[name]" type="text" /&gt;
822
+ &lt;input id="person_address_23_city" name="person[address][23][city]" type="text" /&gt;
823
+ &lt;input id="person_address_45_city" name="person[address][45][city]" type="text" /&gt;
824
+ &lt;/form&gt;
825
+
826
+ </pre>
827
+ </div>
828
+ <p>This will result in a <code>params</code> hash that looks like</p><div class="code_container">
829
+ <pre class="brush: ruby; gutter: false; toolbar: false">
830
+ {'person' =&gt; {'name' =&gt; 'Bob', 'address' =&gt; {'23' =&gt; {'city' =&gt; 'Paris'}, '45' =&gt; {'city' =&gt; 'London'}}}}
831
+
832
+ </pre>
833
+ </div>
834
+ <p>Rails knows that all these inputs should be part of the person hash because you
835
+ called <code>fields_for</code> on the first form builder. By specifying an <code>:index</code> option
836
+ you're telling Rails that instead of naming the inputs <code>person[address][city]</code>
837
+ it should insert that index surrounded by [] between the address and the city.
838
+ This is often useful as it is then easy to locate which Address record
839
+ should be modified. You can pass numbers with some other significance,
840
+ strings or even <code>nil</code> (which will result in an array parameter being created).</p><p>To create more intricate nestings, you can specify the first part of the input
841
+ name (<code>person[address]</code> in the previous example) explicitly:</p><div class="code_container">
842
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
843
+ &lt;%= fields_for 'person[address][primary]', address, index: address do |address_form| %&gt;
844
+ &lt;%= address_form.text_field :city %&gt;
845
+ &lt;% end %&gt;
846
+
847
+ </pre>
848
+ </div>
849
+ <p>will create inputs like</p><div class="code_container">
850
+ <pre class="brush: xml; gutter: false; toolbar: false">
851
+ &lt;input id="person_address_primary_1_city" name="person[address][primary][1][city]" type="text" value="bologna" /&gt;
852
+
853
+ </pre>
854
+ </div>
855
+ <p>As a general rule the final input name is the concatenation of the name given to <code>fields_for</code>/<code>form_for</code>, the index value and the name of the attribute. You can also pass an <code>:index</code> option directly to helpers such as <code>text_field</code>, but it is usually less repetitive to specify this at the form builder level rather than on individual input controls.</p><p>As a shortcut you can append [] to the name and omit the <code>:index</code> option. This is the same as specifying <code>index: address</code> so</p><div class="code_container">
856
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
857
+ &lt;%= fields_for 'person[address][primary][]', address do |address_form| %&gt;
858
+ &lt;%= address_form.text_field :city %&gt;
859
+ &lt;% end %&gt;
860
+
861
+ </pre>
862
+ </div>
863
+ <p>produces exactly the same output as the previous example.</p><h3 id="forms-to-external-resources">8 Forms to External Resources</h3><p>Rails' form helpers can also be used to build a form for posting data to an external resource. However, at times it can be necessary to set an <code>authenticity_token</code> for the resource; this can be done by passing an <code>authenticity_token: 'your_external_token'</code> parameter to the <code>form_tag</code> options:</p><div class="code_container">
864
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
865
+ &lt;%= form_tag 'http://farfar.away/form', authenticity_token: 'external_token' do %&gt;
866
+ Form contents
867
+ &lt;% end %&gt;
868
+
869
+ </pre>
870
+ </div>
871
+ <p>Sometimes when submitting data to an external resource, like a payment gateway, the fields that can be used in the form are limited by an external API and it may be undesirable to generate an <code>authenticity_token</code>. To not send a token, simply pass <code>false</code> to the <code>:authenticity_token</code> option:</p><div class="code_container">
872
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
873
+ &lt;%= form_tag 'http://farfar.away/form', authenticity_token: false do %&gt;
874
+ Form contents
875
+ &lt;% end %&gt;
876
+
877
+ </pre>
878
+ </div>
879
+ <p>The same technique is also available for <code>form_for</code>:</p><div class="code_container">
880
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
881
+ &lt;%= form_for @invoice, url: external_url, authenticity_token: 'external_token' do |f| %&gt;
882
+ Form contents
883
+ &lt;% end %&gt;
884
+
885
+ </pre>
886
+ </div>
887
+ <p>Or if you don't want to render an <code>authenticity_token</code> field:</p><div class="code_container">
888
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
889
+ &lt;%= form_for @invoice, url: external_url, authenticity_token: false do |f| %&gt;
890
+ Form contents
891
+ &lt;% end %&gt;
892
+
893
+ </pre>
894
+ </div>
895
+ <h3 id="building-complex-forms">9 Building Complex Forms</h3><p>Many apps grow beyond simple forms editing a single object. For example when creating a <code>Person</code> you might want to allow the user to (on the same form) create multiple address records (home, work, etc.). When later editing that person the user should be able to add, remove or amend addresses as necessary.</p><h4 id="configuring-the-model">9.1 Configuring the Model</h4><p>Active Record provides model level support via the <code>accepts_nested_attributes_for</code> method:</p><div class="code_container">
896
+ <pre class="brush: ruby; gutter: false; toolbar: false">
897
+ class Person &lt; ActiveRecord::Base
898
+ has_many :addresses
899
+ accepts_nested_attributes_for :addresses
900
+ end
901
+
902
+ class Address &lt; ActiveRecord::Base
903
+ belongs_to :person
904
+ end
905
+
906
+ </pre>
907
+ </div>
908
+ <p>This creates an <code>addresses_attributes=</code> method on <code>Person</code> that allows you to create, update and (optionally) destroy addresses.</p><h4 id="nested-forms">9.2 Nested Forms</h4><p>The following form allows a user to create a <code>Person</code> and its associated addresses.</p><div class="code_container">
909
+ <pre class="brush: plain; gutter: false; toolbar: false">
910
+ &lt;%= form_for @person do |f| %&gt;
911
+ Addresses:
912
+ &lt;ul&gt;
913
+ &lt;%= f.fields_for :addresses do |addresses_form| %&gt;
914
+ &lt;li&gt;
915
+ &lt;%= addresses_form.label :kind %&gt;
916
+ &lt;%= addresses_form.text_field :kind %&gt;
917
+
918
+ &lt;%= addresses_form.label :street %&gt;
919
+ &lt;%= addresses_form.text_field :street %&gt;
920
+ ...
921
+ &lt;/li&gt;
922
+ &lt;% end %&gt;
923
+ &lt;/ul&gt;
924
+ &lt;% end %&gt;
925
+
926
+ </pre>
927
+ </div>
928
+ <p>When an association accepts nested attributes <code>fields_for</code> renders its block once for every element of the association. In particular, if a person has no addresses it renders nothing. A common pattern is for the controller to build one or more empty children so that at least one set of fields is shown to the user. The example below would result in 2 sets of address fields being rendered on the new person form.</p><div class="code_container">
929
+ <pre class="brush: ruby; gutter: false; toolbar: false">
930
+ def new
931
+ @person = Person.new
932
+ 2.times { @person.addresses.build}
933
+ end
934
+
935
+ </pre>
936
+ </div>
937
+ <p>The <code>fields_for</code> yields a form builder. The parameters' name will be what
938
+ <code>accepts_nested_attributes_for</code> expects. For example when creating a user with
939
+ 2 addresses, the submitted parameters would look like:</p><div class="code_container">
940
+ <pre class="brush: ruby; gutter: false; toolbar: false">
941
+ {
942
+ 'person' =&gt; {
943
+ 'name' =&gt; 'John Doe',
944
+ 'addresses_attributes' =&gt; {
945
+ '0' =&gt; {
946
+ 'kind' =&gt; 'Home',
947
+ 'street' =&gt; '221b Baker Street'
948
+ },
949
+ '1' =&gt; {
950
+ 'kind' =&gt; 'Office',
951
+ 'street' =&gt; '31 Spooner Street'
952
+ }
953
+ }
954
+ }
955
+ }
956
+
957
+ </pre>
958
+ </div>
959
+ <p>The keys of the <code>:addresses_attributes</code> hash are unimportant, they need merely be different for each address.</p><p>If the associated object is already saved, <code>fields_for</code> autogenerates a hidden input with the <code>id</code> of the saved record. You can disable this by passing <code>include_id: false</code> to <code>fields_for</code>. You may wish to do this if the autogenerated input is placed in a location where an input tag is not valid HTML or when using an ORM where children do not have an <code>id</code>.</p><h4 id="the-controller">9.3 The Controller</h4><p>As usual you need to
960
+ <a href="action_controller_overview.html#strong-parameters">whitelist the parameters</a> in
961
+ the controller before you pass them to the model:</p><div class="code_container">
962
+ <pre class="brush: ruby; gutter: false; toolbar: false">
963
+ def create
964
+ @person = Person.new(person_params)
965
+ # ...
966
+ end
967
+
968
+ private
969
+ def person_params
970
+ params.require(:person).permit(:name, addresses_attributes: [:id, :kind, :street])
971
+ end
972
+
973
+ </pre>
974
+ </div>
975
+ <h4 id="removing-objects">9.4 Removing Objects</h4><p>You can allow users to delete associated objects by passing <code>allow_destroy: true</code> to <code>accepts_nested_attributes_for</code></p><div class="code_container">
976
+ <pre class="brush: ruby; gutter: false; toolbar: false">
977
+ class Person &lt; ActiveRecord::Base
978
+ has_many :addresses
979
+ accepts_nested_attributes_for :addresses, allow_destroy: true
980
+ end
981
+
982
+ </pre>
983
+ </div>
984
+ <p>If the hash of attributes for an object contains the key <code>_destroy</code> with a value
985
+ of <code>1</code> or <code>true</code> then the object will be destroyed. This form allows users to
986
+ remove addresses:</p><div class="code_container">
987
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
988
+ &lt;%= form_for @person do |f| %&gt;
989
+ Addresses:
990
+ &lt;ul&gt;
991
+ &lt;%= f.fields_for :addresses do |addresses_form| %&gt;
992
+ &lt;li&gt;
993
+ &lt;%= addresses_form.check_box :_destroy%&gt;
994
+ &lt;%= addresses_form.label :kind %&gt;
995
+ &lt;%= addresses_form.text_field :kind %&gt;
996
+ ...
997
+ &lt;/li&gt;
998
+ &lt;% end %&gt;
999
+ &lt;/ul&gt;
1000
+ &lt;% end %&gt;
1001
+
1002
+ </pre>
1003
+ </div>
1004
+ <p>Don't forget to update the whitelisted params in your controller to also include
1005
+ the <code>_destroy</code> field:</p><div class="code_container">
1006
+ <pre class="brush: ruby; gutter: false; toolbar: false">
1007
+ def person_params
1008
+ params.require(:person).
1009
+ permit(:name, addresses_attributes: [:id, :kind, :street, :_destroy])
1010
+ end
1011
+
1012
+ </pre>
1013
+ </div>
1014
+ <h4 id="preventing-empty-records">9.5 Preventing Empty Records</h4><p>It is often useful to ignore sets of fields that the user has not filled in. You can control this by passing a <code>:reject_if</code> proc to <code>accepts_nested_attributes_for</code>. This proc will be called with each hash of attributes submitted by the form. If the proc returns <code>false</code> then Active Record will not build an associated object for that hash. The example below only tries to build an address if the <code>kind</code> attribute is set.</p><div class="code_container">
1015
+ <pre class="brush: ruby; gutter: false; toolbar: false">
1016
+ class Person &lt; ActiveRecord::Base
1017
+ has_many :addresses
1018
+ accepts_nested_attributes_for :addresses, reject_if: lambda {|attributes| attributes['kind'].blank?}
1019
+ end
1020
+
1021
+ </pre>
1022
+ </div>
1023
+ <p>As a convenience you can instead pass the symbol <code>:all_blank</code> which will create a proc that will reject records where all the attributes are blank excluding any value for <code>_destroy</code>.</p><h4 id="adding-fields-on-the-fly">9.6 Adding Fields on the Fly</h4><p>Rather than rendering multiple sets of fields ahead of time you may wish to add them only when a user clicks on an 'Add new address' button. Rails does not provide any built-in support for this. When generating new sets of fields you must ensure the key of the associated array is unique - the current JavaScript date (milliseconds after the epoch) is a common choice.</p>
1024
+
1025
+ <h3>Feedback</h3>
1026
+ <p>
1027
+ You're encouraged to help improve the quality of this guide.
1028
+ </p>
1029
+ <p>
1030
+ Please contribute if you see any typos or factual errors.
1031
+ To get started, you can read our <a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section.
1032
+ </p>
1033
+ <p>
1034
+ You may also find incomplete content, or stuff that is not up to date.
1035
+ Please do add any missing documentation for master. Make sure to check
1036
+ <a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
1037
+ if the issues are already fixed or not on the master branch.
1038
+ Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
1039
+ for style and conventions.
1040
+ </p>
1041
+ <p>
1042
+ If for whatever reason you spot something to fix but cannot patch it yourself, please
1043
+ <a href="https://github.com/rails/rails/issues">open an issue</a>.
1044
+ </p>
1045
+ <p>And last but not least, any kind of discussion regarding Ruby on Rails
1046
+ documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
1047
+ </p>
1048
+ </div>
1049
+ </div>
1050
+ </div>
1051
+
1052
+ <hr class="hide" />
1053
+ <div id="footer">
1054
+ <div class="wrapper">
1055
+ <p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p>
1056
+ <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
1057
+
1058
+ </div>
1059
+ </div>
1060
+
1061
+ <script type="text/javascript" src="javascripts/jquery.min.js"></script>
1062
+ <script type="text/javascript" src="javascripts/responsive-tables.js"></script>
1063
+ <script type="text/javascript" src="javascripts/guides.js"></script>
1064
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
1065
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
1066
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
1067
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
1068
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
1069
+ <script type="text/javascript">
1070
+ SyntaxHighlighter.all();
1071
+ $(guidesIndex.bind);
1072
+ </script>
1073
+ </body>
1074
+ </html>