rails 4.2.0.beta4 → 4.2.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/guides/Rakefile +3 -1
  3. data/guides/bug_report_templates/action_controller_gem.rb +2 -2
  4. data/guides/bug_report_templates/action_controller_master.rb +2 -2
  5. data/guides/source/3_0_release_notes.md +2 -2
  6. data/guides/source/4_1_release_notes.md +1 -1
  7. data/guides/source/4_2_release_notes.md +250 -225
  8. data/guides/source/_welcome.html.erb +1 -1
  9. data/guides/source/action_controller_overview.md +6 -6
  10. data/guides/source/action_mailer_basics.md +26 -11
  11. data/guides/source/action_view_overview.md +0 -1
  12. data/guides/source/active_job_basics.md +29 -23
  13. data/guides/source/active_record_postgresql.md +2 -7
  14. data/guides/source/active_record_validations.md +1 -0
  15. data/guides/source/active_support_core_extensions.md +1 -1
  16. data/guides/source/active_support_instrumentation.md +5 -5
  17. data/guides/source/asset_pipeline.md +2 -2
  18. data/guides/source/association_basics.md +0 -2
  19. data/guides/source/command_line.md +6 -15
  20. data/guides/source/configuring.md +4 -4
  21. data/guides/source/documents.yaml +0 -1
  22. data/guides/source/engines.md +26 -15
  23. data/guides/source/form_helpers.md +10 -2
  24. data/guides/source/getting_started.md +9 -9
  25. data/guides/source/rails_on_rack.md +2 -2
  26. data/guides/source/ruby_on_rails_guides_guidelines.md +1 -0
  27. data/guides/source/security.md +1 -1
  28. data/guides/source/testing.md +80 -13
  29. data/guides/source/upgrading_ruby_on_rails.md +23 -20
  30. metadata +29 -229
  31. data/guides/output/2_2_release_notes.html +0 -724
  32. data/guides/output/2_3_release_notes.html +0 -870
  33. data/guides/output/3_0_release_notes.html +0 -773
  34. data/guides/output/3_1_release_notes.html +0 -740
  35. data/guides/output/3_2_release_notes.html +0 -797
  36. data/guides/output/4_0_release_notes.html +0 -523
  37. data/guides/output/4_1_release_notes.html +0 -806
  38. data/guides/output/4_2_release_notes.html +0 -728
  39. data/guides/output/Gemfile +0 -6
  40. data/guides/output/_license.html +0 -226
  41. data/guides/output/_welcome.html +0 -233
  42. data/guides/output/action_controller_overview.html +0 -1335
  43. data/guides/output/action_mailer_basics.html +0 -928
  44. data/guides/output/action_view_overview.html +0 -1509
  45. data/guides/output/active_job_basics.html +0 -546
  46. data/guides/output/active_model_basics.html +0 -438
  47. data/guides/output/active_record_basics.html +0 -594
  48. data/guides/output/active_record_callbacks.html +0 -592
  49. data/guides/output/active_record_migrations.html +0 -1123
  50. data/guides/output/active_record_postgresql.html +0 -675
  51. data/guides/output/active_record_querying.html +0 -1796
  52. data/guides/output/active_record_validations.html +0 -1301
  53. data/guides/output/active_support_core_extensions.html +0 -3450
  54. data/guides/output/active_support_instrumentation.html +0 -1121
  55. data/guides/output/api_documentation_guidelines.html +0 -498
  56. data/guides/output/asset_pipeline.html +0 -1167
  57. data/guides/output/association_basics.html +0 -2086
  58. data/guides/output/caching_with_rails.html +0 -553
  59. data/guides/output/command_line.html +0 -791
  60. data/guides/output/configuring.html +0 -1055
  61. data/guides/output/contributing_to_ruby_on_rails.html +0 -657
  62. data/guides/output/credits.html +0 -284
  63. data/guides/output/debugging_rails_applications.html +0 -1014
  64. data/guides/output/development_dependencies_install.html +0 -478
  65. data/guides/output/engines.html +0 -1438
  66. data/guides/output/form_helpers.html +0 -1074
  67. data/guides/output/generators.html +0 -838
  68. data/guides/output/getting_started.html +0 -2092
  69. data/guides/output/i18n.html +0 -1198
  70. data/guides/output/images/akshaysurve.jpg +0 -0
  71. data/guides/output/images/belongs_to.png +0 -0
  72. data/guides/output/images/book_icon.gif +0 -0
  73. data/guides/output/images/bullet.gif +0 -0
  74. data/guides/output/images/chapters_icon.gif +0 -0
  75. data/guides/output/images/check_bullet.gif +0 -0
  76. data/guides/output/images/credits_pic_blank.gif +0 -0
  77. data/guides/output/images/csrf.png +0 -0
  78. data/guides/output/images/edge_badge.png +0 -0
  79. data/guides/output/images/favicon.ico +0 -0
  80. data/guides/output/images/feature_tile.gif +0 -0
  81. data/guides/output/images/footer_tile.gif +0 -0
  82. data/guides/output/images/fxn.png +0 -0
  83. data/guides/output/images/getting_started/article_with_comments.png +0 -0
  84. data/guides/output/images/getting_started/challenge.png +0 -0
  85. data/guides/output/images/getting_started/confirm_dialog.png +0 -0
  86. data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  87. data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  88. data/guides/output/images/getting_started/form_with_errors.png +0 -0
  89. data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
  90. data/guides/output/images/getting_started/new_article.png +0 -0
  91. data/guides/output/images/getting_started/new_post.png +0 -0
  92. data/guides/output/images/getting_started/post_with_comments.png +0 -0
  93. data/guides/output/images/getting_started/rails_welcome.png +0 -0
  94. data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
  95. data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
  96. data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
  97. data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
  98. data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
  99. data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
  100. data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
  101. data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
  102. data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
  103. data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
  104. data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
  105. data/guides/output/images/grey_bullet.gif +0 -0
  106. data/guides/output/images/habtm.png +0 -0
  107. data/guides/output/images/has_many.png +0 -0
  108. data/guides/output/images/has_many_through.png +0 -0
  109. data/guides/output/images/has_one.png +0 -0
  110. data/guides/output/images/has_one_through.png +0 -0
  111. data/guides/output/images/header_backdrop.png +0 -0
  112. data/guides/output/images/header_tile.gif +0 -0
  113. data/guides/output/images/i18n/demo_html_safe.png +0 -0
  114. data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
  115. data/guides/output/images/i18n/demo_translated_en.png +0 -0
  116. data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
  117. data/guides/output/images/i18n/demo_translation_missing.png +0 -0
  118. data/guides/output/images/i18n/demo_untranslated.png +0 -0
  119. data/guides/output/images/icons/README +0 -5
  120. data/guides/output/images/icons/callouts/1.png +0 -0
  121. data/guides/output/images/icons/callouts/10.png +0 -0
  122. data/guides/output/images/icons/callouts/11.png +0 -0
  123. data/guides/output/images/icons/callouts/12.png +0 -0
  124. data/guides/output/images/icons/callouts/13.png +0 -0
  125. data/guides/output/images/icons/callouts/14.png +0 -0
  126. data/guides/output/images/icons/callouts/15.png +0 -0
  127. data/guides/output/images/icons/callouts/2.png +0 -0
  128. data/guides/output/images/icons/callouts/3.png +0 -0
  129. data/guides/output/images/icons/callouts/4.png +0 -0
  130. data/guides/output/images/icons/callouts/5.png +0 -0
  131. data/guides/output/images/icons/callouts/6.png +0 -0
  132. data/guides/output/images/icons/callouts/7.png +0 -0
  133. data/guides/output/images/icons/callouts/8.png +0 -0
  134. data/guides/output/images/icons/callouts/9.png +0 -0
  135. data/guides/output/images/icons/caution.png +0 -0
  136. data/guides/output/images/icons/example.png +0 -0
  137. data/guides/output/images/icons/home.png +0 -0
  138. data/guides/output/images/icons/important.png +0 -0
  139. data/guides/output/images/icons/next.png +0 -0
  140. data/guides/output/images/icons/note.png +0 -0
  141. data/guides/output/images/icons/prev.png +0 -0
  142. data/guides/output/images/icons/tip.png +0 -0
  143. data/guides/output/images/icons/up.png +0 -0
  144. data/guides/output/images/icons/warning.png +0 -0
  145. data/guides/output/images/nav_arrow.gif +0 -0
  146. data/guides/output/images/oscardelben.jpg +0 -0
  147. data/guides/output/images/polymorphic.png +0 -0
  148. data/guides/output/images/radar.png +0 -0
  149. data/guides/output/images/rails4_features.png +0 -0
  150. data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
  151. data/guides/output/images/rails_guides_logo.gif +0 -0
  152. data/guides/output/images/rails_logo_remix.gif +0 -0
  153. data/guides/output/images/session_fixation.png +0 -0
  154. data/guides/output/images/tab_grey.gif +0 -0
  155. data/guides/output/images/tab_info.gif +0 -0
  156. data/guides/output/images/tab_note.gif +0 -0
  157. data/guides/output/images/tab_red.gif +0 -0
  158. data/guides/output/images/tab_yellow.gif +0 -0
  159. data/guides/output/images/tab_yellow.png +0 -0
  160. data/guides/output/images/vijaydev.jpg +0 -0
  161. data/guides/output/index.html +0 -354
  162. data/guides/output/initialization.html +0 -876
  163. data/guides/output/javascripts/guides.js +0 -59
  164. data/guides/output/javascripts/jquery.min.js +0 -4
  165. data/guides/output/javascripts/responsive-tables.js +0 -43
  166. data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  167. data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  168. data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  169. data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  170. data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  171. data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  172. data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  173. data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  174. data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  175. data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  176. data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  177. data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  178. data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  179. data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  180. data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  181. data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  182. data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  183. data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  184. data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  185. data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  186. data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  187. data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  188. data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  189. data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  190. data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  191. data/guides/output/javascripts/syntaxhighlighter/shCore.js +0 -17
  192. data/guides/output/layout.html +0 -448
  193. data/guides/output/layouts_and_rendering.html +0 -1541
  194. data/guides/output/maintenance_policy.html +0 -257
  195. data/guides/output/migrations.html +0 -1360
  196. data/guides/output/nested_model_forms.html +0 -412
  197. data/guides/output/plugins.html +0 -644
  198. data/guides/output/rails_application_templates.html +0 -450
  199. data/guides/output/rails_on_rack.html +0 -547
  200. data/guides/output/routing.html +0 -1631
  201. data/guides/output/ruby_on_rails_guides_guidelines.html +0 -329
  202. data/guides/output/security.html +0 -935
  203. data/guides/output/stylesheets/fixes.css +0 -16
  204. data/guides/output/stylesheets/kindle.css +0 -11
  205. data/guides/output/stylesheets/main.css +0 -713
  206. data/guides/output/stylesheets/print.css +0 -52
  207. data/guides/output/stylesheets/reset.css +0 -43
  208. data/guides/output/stylesheets/responsive-tables.css +0 -50
  209. data/guides/output/stylesheets/style.css +0 -13
  210. data/guides/output/stylesheets/syntaxhighlighter/shCore.css +0 -226
  211. data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  212. data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  213. data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  214. data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  215. data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  216. data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  217. data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  218. data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  219. data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  220. data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  221. data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  222. data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  223. data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  224. data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  225. data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  226. data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  227. data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  228. data/guides/output/testing.html +0 -1350
  229. data/guides/output/upgrading_ruby_on_rails.html +0 -1135
  230. data/guides/output/working_with_javascript_in_rails.html +0 -587
@@ -1,675 +0,0 @@
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>Active Record and PostgreSQL — 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>Active Record and PostgreSQL</h2><p>This guide covers PostgreSQL specific usage of Active Record.</p><p>After reading this guide, you will know:</p>
165
- <ul>
166
- <li>How to use PostgreSQL&#39;s datatypes.</li>
167
- <li>How to use UUID primary keys.</li>
168
- <li>How to implement full text search with PostgreSQL.</li>
169
- <li>How to back your Active Record models with database views.</li>
170
- </ul>
171
-
172
-
173
- <div id="subCol">
174
- <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
175
- <ol class="chapters">
176
- <li>
177
- <a href="#datatypes">Datatypes</a>
178
-
179
- <ul>
180
- <li><a href="#bytea">Bytea</a></li>
181
- <li><a href="#array">Array</a></li>
182
- <li><a href="#hstore">Hstore</a></li>
183
- <li><a href="#json">JSON</a></li>
184
- <li><a href="#range-types">Range Types</a></li>
185
- <li><a href="#composite-types">Composite Types</a></li>
186
- <li><a href="#enumerated-types">Enumerated Types</a></li>
187
- <li><a href="#uuid">UUID</a></li>
188
- <li><a href="#bit-string-types">Bit String Types</a></li>
189
- <li><a href="#network-address-types">Network Address Types</a></li>
190
- <li><a href="#geometric-types">Geometric Types</a></li>
191
- </ul>
192
- </li>
193
- <li><a href="#uuid-primary-keys">UUID Primary Keys</a></li>
194
- <li><a href="#full-text-search">Full Text Search</a></li>
195
- <li><a href="#database-views">Database Views</a></li>
196
- </ol>
197
-
198
- </div>
199
-
200
- </div>
201
- </div>
202
-
203
- <div id="container">
204
- <div class="wrapper">
205
- <div id="mainCol">
206
- <p>In order to use the PostgreSQL adapter you need to have at least version 8.2
207
- installed. Older versions are not supported.</p><p>To get started with PostgreSQL have a look at the
208
- <a href="configuring.html#configuring-a-postgresql-database">configuring Rails guide</a>.
209
- It describes how to properly setup Active Record for PostgreSQL.</p><h3 id="datatypes">1 Datatypes</h3><p>PostgreSQL offers a number of specific datatypes. Following is a list of types,
210
- that are supported by the PostgreSQL adapter.</p><h4 id="bytea">1.1 Bytea</h4>
211
- <ul>
212
- <li><a href="http://www.postgresql.org/docs/9.3/static/datatype-binary.html">type definition</a></li>
213
- <li><a href="http://www.postgresql.org/docs/9.3/static/functions-binarystring.html">functions and operators</a></li>
214
- </ul>
215
- <div class="code_container">
216
- <pre class="brush: ruby; gutter: false; toolbar: false">
217
- # db/migrate/20140207133952_create_documents.rb
218
- create_table :documents do |t|
219
- t.binary 'payload'
220
- end
221
-
222
- # app/models/document.rb
223
- class Document &lt; ActiveRecord::Base
224
- end
225
-
226
- # Usage
227
- data = File.read(Rails.root + "tmp/output.pdf")
228
- Document.create payload: data
229
-
230
- </pre>
231
- </div>
232
- <h4 id="array">1.2 Array</h4>
233
- <ul>
234
- <li><a href="http://www.postgresql.org/docs/9.3/static/arrays.html">type definition</a></li>
235
- <li><a href="http://www.postgresql.org/docs/9.3/static/functions-array.html">functions and operators</a></li>
236
- </ul>
237
- <div class="code_container">
238
- <pre class="brush: ruby; gutter: false; toolbar: false">
239
- # db/migrate/20140207133952_create_books.rb
240
- create_table :books do |t|
241
- t.string 'title'
242
- t.string 'tags', array: true
243
- t.integer 'ratings', array: true
244
- end
245
- add_index :books, :tags, using: 'gin'
246
- add_index :books, :ratings, using: 'gin'
247
-
248
- # app/models/book.rb
249
- class Book &lt; ActiveRecord::Base
250
- end
251
-
252
- # Usage
253
- Book.create title: "Brave New World",
254
- tags: ["fantasy", "fiction"],
255
- ratings: [4, 5]
256
-
257
- ## Books for a single tag
258
- Book.where("'fantasy' = ANY (tags)")
259
-
260
- ## Books for multiple tags
261
- Book.where("tags @&gt; ARRAY[?]::varchar[]", ["fantasy", "fiction"])
262
-
263
- ## Books with 3 or more ratings
264
- Book.where("array_length(ratings, 1) &gt;= 3")
265
-
266
- </pre>
267
- </div>
268
- <h4 id="hstore">1.3 Hstore</h4>
269
- <ul>
270
- <li><a href="http://www.postgresql.org/docs/9.3/static/hstore.html">type definition</a></li>
271
- </ul>
272
- <div class="code_container">
273
- <pre class="brush: ruby; gutter: false; toolbar: false">
274
- # db/migrate/20131009135255_create_profiles.rb
275
- ActiveRecord::Schema.define do
276
- create_table :profiles do |t|
277
- t.hstore 'settings'
278
- end
279
- end
280
-
281
- # app/models/profile.rb
282
- class Profile &lt; ActiveRecord::Base
283
- end
284
-
285
- # Usage
286
- Profile.create(settings: { "color" =&gt; "blue", "resolution" =&gt; "800x600" })
287
-
288
- profile = Profile.first
289
- profile.settings # =&gt; {"color"=&gt;"blue", "resolution"=&gt;"800x600"}
290
-
291
- profile.settings = {"color" =&gt; "yellow", "resolution" =&gt; "1280x1024"}
292
- profile.save!
293
-
294
- ## you need to call _will_change! if you are editing the store in place
295
- profile.settings["color"] = "green"
296
- profile.settings_will_change!
297
- profile.save!
298
-
299
- </pre>
300
- </div>
301
- <h4 id="json">1.4 JSON</h4>
302
- <ul>
303
- <li><a href="http://www.postgresql.org/docs/9.3/static/datatype-json.html">type definition</a></li>
304
- <li><a href="http://www.postgresql.org/docs/9.3/static/functions-json.html">functions and operators</a></li>
305
- </ul>
306
- <div class="code_container">
307
- <pre class="brush: ruby; gutter: false; toolbar: false">
308
- # db/migrate/20131220144913_create_events.rb
309
- create_table :events do |t|
310
- t.json 'payload'
311
- end
312
-
313
- # app/models/event.rb
314
- class Event &lt; ActiveRecord::Base
315
- end
316
-
317
- # Usage
318
- Event.create(payload: { kind: "user_renamed", change: ["jack", "john"]})
319
-
320
- event = Event.first
321
- event.payload # =&gt; {"kind"=&gt;"user_renamed", "change"=&gt;["jack", "john"]}
322
-
323
- ## Query based on JSON document
324
- Event.where("payload-&gt;'kind' = ?", "user_renamed")
325
-
326
- </pre>
327
- </div>
328
- <h4 id="range-types">1.5 Range Types</h4>
329
- <ul>
330
- <li><a href="http://www.postgresql.org/docs/9.3/static/rangetypes.html">type definition</a></li>
331
- <li><a href="http://www.postgresql.org/docs/9.3/static/functions-range.html">functions and operators</a></li>
332
- </ul>
333
- <p>This type is mapped to Ruby <a href="http://www.ruby-doc.org/core-2.1.1/Range.html"><code>Range</code></a> objects.</p><div class="code_container">
334
- <pre class="brush: ruby; gutter: false; toolbar: false">
335
- # db/migrate/20130923065404_create_events.rb
336
- create_table :events do |t|
337
- t.daterange 'duration'
338
- end
339
-
340
- # app/models/event.rb
341
- class Event &lt; ActiveRecord::Base
342
- end
343
-
344
- # Usage
345
- Event.create(duration: Date.new(2014, 2, 11)..Date.new(2014, 2, 12))
346
-
347
- event = Event.first
348
- event.duration # =&gt; Tue, 11 Feb 2014...Thu, 13 Feb 2014
349
-
350
- ## All Events on a given date
351
- Event.where("duration @&gt; ?::date", Date.new(2014, 2, 12))
352
-
353
- ## Working with range bounds
354
- event = Event.
355
- select("lower(duration) AS starts_at").
356
- select("upper(duration) AS ends_at").first
357
-
358
- event.starts_at # =&gt; Tue, 11 Feb 2014
359
- event.ends_at # =&gt; Thu, 13 Feb 2014
360
-
361
- </pre>
362
- </div>
363
- <h4 id="composite-types">1.6 Composite Types</h4>
364
- <ul>
365
- <li><a href="http://www.postgresql.org/docs/9.3/static/rowtypes.html">type definition</a></li>
366
- </ul>
367
- <p>Currently there is no special support for composite types. They are mapped to
368
- normal text columns:</p><div class="code_container">
369
- <pre class="brush: sql; gutter: false; toolbar: false">
370
- CREATE TYPE full_address AS
371
- (
372
- city VARCHAR(90),
373
- street VARCHAR(90)
374
- );
375
-
376
- </pre>
377
- </div>
378
- <div class="code_container">
379
- <pre class="brush: ruby; gutter: false; toolbar: false">
380
- # db/migrate/20140207133952_create_contacts.rb
381
- execute &lt;&lt;-SQL
382
- CREATE TYPE full_address AS
383
- (
384
- city VARCHAR(90),
385
- street VARCHAR(90)
386
- );
387
- SQL
388
- create_table :contacts do |t|
389
- t.column :address, :full_address
390
- end
391
-
392
- # app/models/contact.rb
393
- class Contact &lt; ActiveRecord::Base
394
- end
395
-
396
- # Usage
397
- Contact.create address: "(Paris,Champs-Élysées)"
398
- contact = Contact.first
399
- contact.address # =&gt; "(Paris,Champs-Élysées)"
400
- contact.address = "(Paris,Rue Basse)"
401
- contact.save!
402
-
403
- </pre>
404
- </div>
405
- <h4 id="enumerated-types">1.7 Enumerated Types</h4>
406
- <ul>
407
- <li><a href="http://www.postgresql.org/docs/9.3/static/datatype-enum.html">type definition</a></li>
408
- </ul>
409
- <p>Currently there is no special support for enumerated types. They are mapped as
410
- normal text columns:</p><div class="code_container">
411
- <pre class="brush: ruby; gutter: false; toolbar: false">
412
- # db/migrate/20131220144913_create_events.rb
413
- execute &lt;&lt;-SQL
414
- CREATE TYPE article_status AS ENUM ('draft', 'published');
415
- SQL
416
- create_table :articles do |t|
417
- t.column :status, :article_status
418
- end
419
-
420
- # app/models/article.rb
421
- class Article &lt; ActiveRecord::Base
422
- end
423
-
424
- # Usage
425
- Article.create status: "draft"
426
- article = Article.first
427
- article.status # =&gt; "draft"
428
-
429
- article.status = "published"
430
- article.save!
431
-
432
- </pre>
433
- </div>
434
- <h4 id="uuid">1.8 UUID</h4>
435
- <ul>
436
- <li><a href="http://www.postgresql.org/docs/9.3/static/datatype-uuid.html">type definition</a></li>
437
- <li><a href="http://www.postgresql.org/docs/9.3/static/uuid-ossp.html">generator functions</a></li>
438
- </ul>
439
- <div class="code_container">
440
- <pre class="brush: ruby; gutter: false; toolbar: false">
441
- # db/migrate/20131220144913_create_revisions.rb
442
- create_table :revisions do |t|
443
- t.column :identifier, :uuid
444
- end
445
-
446
- # app/models/revision.rb
447
- class Revision &lt; ActiveRecord::Base
448
- end
449
-
450
- # Usage
451
- Revision.create identifier: "A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11"
452
-
453
- revision = Revision.first
454
- revision.identifier # =&gt; "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"
455
-
456
- </pre>
457
- </div>
458
- <h4 id="bit-string-types">1.9 Bit String Types</h4>
459
- <ul>
460
- <li><a href="http://www.postgresql.org/docs/9.3/static/datatype-bit.html">type definition</a></li>
461
- <li><a href="http://www.postgresql.org/docs/9.3/static/functions-bitstring.html">functions and operators</a></li>
462
- </ul>
463
- <div class="code_container">
464
- <pre class="brush: ruby; gutter: false; toolbar: false">
465
- # db/migrate/20131220144913_create_users.rb
466
- create_table :users, force: true do |t|
467
- t.column :settings, "bit(8)"
468
- end
469
-
470
- # app/models/device.rb
471
- class User &lt; ActiveRecord::Base
472
- end
473
-
474
- # Usage
475
- User.create settings: "01010011"
476
- user = User.first
477
- user.settings # =&gt; "(Paris,Champs-Élysées)"
478
- user.settings = "0xAF"
479
- user.settings # =&gt; 10101111
480
- user.save!
481
-
482
- </pre>
483
- </div>
484
- <h4 id="network-address-types">1.10 Network Address Types</h4>
485
- <ul>
486
- <li><a href="http://www.postgresql.org/docs/9.3/static/datatype-net-types.html">type definition</a></li>
487
- </ul>
488
- <p>The types <code>inet</code> and <code>cidr</code> are mapped to Ruby
489
- <a href="http://www.ruby-doc.org/stdlib-2.1.1/libdoc/ipaddr/rdoc/IPAddr.html"><code>IPAddr</code></a>
490
- objects. The <code>macaddr</code> type is mapped to normal text.</p><div class="code_container">
491
- <pre class="brush: ruby; gutter: false; toolbar: false">
492
- # db/migrate/20140508144913_create_devices.rb
493
- create_table(:devices, force: true) do |t|
494
- t.inet 'ip'
495
- t.cidr 'network'
496
- t.macaddr 'address'
497
- end
498
-
499
- # app/models/device.rb
500
- class Device &lt; ActiveRecord::Base
501
- end
502
-
503
- # Usage
504
- macbook = Device.create(ip: "192.168.1.12",
505
- network: "192.168.2.0/24",
506
- address: "32:01:16:6d:05:ef")
507
-
508
- macbook.ip
509
- # =&gt; #&lt;IPAddr: IPv4:192.168.1.12/255.255.255.255&gt;
510
-
511
- macbook.network
512
- # =&gt; #&lt;IPAddr: IPv4:192.168.2.0/255.255.255.0&gt;
513
-
514
- macbook.address
515
- # =&gt; "32:01:16:6d:05:ef"
516
-
517
- </pre>
518
- </div>
519
- <h4 id="geometric-types">1.11 Geometric Types</h4>
520
- <ul>
521
- <li><a href="http://www.postgresql.org/docs/9.3/static/datatype-geometric.html">type definition</a></li>
522
- </ul>
523
- <p>All geometric types, with the exception of <code>points</code> are mapped to normal text.
524
- A point is casted to an array containing <code>x</code> and <code>y</code> coordinates.</p><h3 id="uuid-primary-keys">2 UUID Primary Keys</h3><div class="note"><p>you need to enable the <code>uuid-ossp</code> extension to generate UUIDs.</p></div><div class="code_container">
525
- <pre class="brush: ruby; gutter: false; toolbar: false">
526
- # db/migrate/20131220144913_create_devices.rb
527
- enable_extension 'uuid-ossp' unless extension_enabled?('uuid-ossp')
528
- create_table :devices, id: :uuid, default: 'uuid_generate_v4()' do |t|
529
- t.string :kind
530
- end
531
-
532
- # app/models/device.rb
533
- class Device &lt; ActiveRecord::Base
534
- end
535
-
536
- # Usage
537
- device = Device.create
538
- device.id # =&gt; "814865cd-5a1d-4771-9306-4268f188fe9e"
539
-
540
- </pre>
541
- </div>
542
- <h3 id="full-text-search">3 Full Text Search</h3><div class="code_container">
543
- <pre class="brush: ruby; gutter: false; toolbar: false">
544
- # db/migrate/20131220144913_create_documents.rb
545
- create_table :documents do |t|
546
- t.string 'title'
547
- t.string 'body'
548
- end
549
-
550
- execute "CREATE INDEX documents_idx ON documents USING gin(to_tsvector('english', title || ' ' || body));"
551
-
552
- # app/models/document.rb
553
- class Document &lt; ActiveRecord::Base
554
- end
555
-
556
- # Usage
557
- Document.create(title: "Cats and Dogs", body: "are nice!")
558
-
559
- ## all documents matching 'cat &amp; dog'
560
- Document.where("to_tsvector('english', title || ' ' || body) @@ to_tsquery(?)",
561
- "cat &amp; dog")
562
-
563
- </pre>
564
- </div>
565
- <h3 id="database-views">4 Database Views</h3>
566
- <ul>
567
- <li><a href="http://www.postgresql.org/docs/9.3/static/sql-createview.html">view creation</a></li>
568
- </ul>
569
- <p>Imagine you need to work with a legacy database containing the following table:</p><div class="code_container">
570
- <pre class="brush: plain; gutter: false; toolbar: false">
571
- rails_pg_guide=# \d "TBL_ART"
572
- Table "public.TBL_ART"
573
- Column | Type | Modifiers
574
- ------------+-----------------------------+------------------------------------------------------------
575
- INT_ID | integer | not null default nextval('"TBL_ART_INT_ID_seq"'::regclass)
576
- STR_TITLE | character varying |
577
- STR_STAT | character varying | default 'draft'::character varying
578
- DT_PUBL_AT | timestamp without time zone |
579
- BL_ARCH | boolean | default false
580
- Indexes:
581
- "TBL_ART_pkey" PRIMARY KEY, btree ("INT_ID")
582
-
583
- </pre>
584
- </div>
585
- <p>This table does not follow the Rails conventions at all.
586
- Because simple PostgreSQL views are updateable by default,
587
- we can wrap it as follows:</p><div class="code_container">
588
- <pre class="brush: ruby; gutter: false; toolbar: false">
589
- # db/migrate/20131220144913_create_articles_view.rb
590
- execute &lt;&lt;-SQL
591
- CREATE VIEW articles AS
592
- SELECT "INT_ID" AS id,
593
- "STR_TITLE" AS title,
594
- "STR_STAT" AS status,
595
- "DT_PUBL_AT" AS published_at,
596
- "BL_ARCH" AS archived
597
- FROM "TBL_ART"
598
- WHERE "BL_ARCH" = 'f'
599
- SQL
600
-
601
- # app/models/article.rb
602
- class Article &lt; ActiveRecord::Base
603
- self.primary_key = "id"
604
- def archive!
605
- update_attribute :archived, true
606
- end
607
- end
608
-
609
- # Usage
610
- first = Article.create! title: "Winter is coming",
611
- status: "published",
612
- published_at: 1.year.ago
613
- second = Article.create! title: "Brace yourself",
614
- status: "draft",
615
- published_at: 1.month.ago
616
-
617
- Article.count # =&gt; 1
618
- first.archive!
619
- Article.count # =&gt; 2
620
-
621
- </pre>
622
- </div>
623
- <div class="note"><p>This application only cares about non-archived <code>Articles</code>. A view also
624
- allows for conditions so we can exclude the archived <code>Articles</code> directly.</p></div>
625
-
626
- <h3>Feedback</h3>
627
- <p>
628
- You're encouraged to help improve the quality of this guide.
629
- </p>
630
- <p>
631
- Please contribute if you see any typos or factual errors.
632
- 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.
633
- </p>
634
- <p>
635
- You may also find incomplete content, or stuff that is not up to date.
636
- Please do add any missing documentation for master. Make sure to check
637
- <a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
638
- if the issues are already fixed or not on the master branch.
639
- Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
640
- for style and conventions.
641
- </p>
642
- <p>
643
- If for whatever reason you spot something to fix but cannot patch it yourself, please
644
- <a href="https://github.com/rails/rails/issues">open an issue</a>.
645
- </p>
646
- <p>And last but not least, any kind of discussion regarding Ruby on Rails
647
- documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
648
- </p>
649
- </div>
650
- </div>
651
- </div>
652
-
653
- <hr class="hide" />
654
- <div id="footer">
655
- <div class="wrapper">
656
- <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>
657
- <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
658
-
659
- </div>
660
- </div>
661
-
662
- <script type="text/javascript" src="javascripts/jquery.min.js"></script>
663
- <script type="text/javascript" src="javascripts/responsive-tables.js"></script>
664
- <script type="text/javascript" src="javascripts/guides.js"></script>
665
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
666
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
667
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
668
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
669
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
670
- <script type="text/javascript">
671
- SyntaxHighlighter.all();
672
- $(guidesIndex.bind);
673
- </script>
674
- </body>
675
- </html>