railties 3.1.1 → 3.1.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +2382 -0
- data/guides/output/2_2_release_notes.html +565 -0
- data/guides/output/2_3_release_notes.html +713 -0
- data/guides/output/3_0_release_notes.html +652 -0
- data/guides/output/3_1_release_notes.html +670 -0
- data/guides/output/action_controller_overview.html +925 -0
- data/guides/output/action_mailer_basics.html +658 -0
- data/guides/output/action_view_overview.html +1471 -0
- data/guides/output/active_model_basics.html +349 -0
- data/guides/output/active_record_basics.html +364 -0
- data/guides/output/active_record_querying.html +1272 -0
- data/guides/output/active_record_validations_callbacks.html +1292 -0
- data/guides/output/active_resource_basics.html +252 -0
- data/guides/output/active_support_core_extensions.html +3374 -0
- data/guides/output/ajax_on_rails.html +412 -0
- data/guides/output/api_documentation_guidelines.html +317 -0
- data/guides/output/asset_pipeline.html +691 -0
- data/guides/output/association_basics.html +1742 -0
- data/guides/output/caching_with_rails.html +533 -0
- data/guides/output/command_line.html +662 -0
- data/guides/output/configuring.html +811 -0
- data/guides/output/contribute.html +216 -0
- data/guides/output/contributing_to_ruby_on_rails.html +465 -0
- data/guides/output/credits.html +210 -0
- data/guides/output/debugging_rails_applications.html +791 -0
- data/guides/output/engines.html +673 -0
- data/guides/output/form_helpers.html +850 -0
- data/guides/output/generators.html +725 -0
- data/guides/output/getting_started.html +1980 -0
- data/guides/output/i18n.html +1054 -0
- data/guides/output/images/belongs_to.png +0 -0
- data/guides/output/images/book_icon.gif +0 -0
- data/guides/output/images/bullet.gif +0 -0
- data/guides/output/images/challenge.png +0 -0
- data/guides/output/images/chapters_icon.gif +0 -0
- data/guides/output/images/check_bullet.gif +0 -0
- data/guides/output/images/credits_pic_blank.gif +0 -0
- data/guides/output/images/csrf.png +0 -0
- data/guides/output/images/customized_error_messages.png +0 -0
- data/guides/output/images/edge_badge.png +0 -0
- data/guides/output/images/error_messages.png +0 -0
- data/guides/output/images/feature_tile.gif +0 -0
- data/guides/output/images/footer_tile.gif +0 -0
- data/guides/output/images/fxn.png +0 -0
- data/guides/output/images/grey_bullet.gif +0 -0
- data/guides/output/images/habtm.png +0 -0
- data/guides/output/images/has_many.png +0 -0
- data/guides/output/images/has_many_through.png +0 -0
- data/guides/output/images/has_one.png +0 -0
- data/guides/output/images/has_one_through.png +0 -0
- data/guides/output/images/header_backdrop.png +0 -0
- data/guides/output/images/header_tile.gif +0 -0
- data/guides/output/images/i18n/demo_html_safe.png +0 -0
- data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translated_en.png +0 -0
- data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translation_missing.png +0 -0
- data/guides/output/images/i18n/demo_untranslated.png +0 -0
- data/guides/output/images/icons/README +5 -0
- data/guides/output/images/icons/callouts/1.png +0 -0
- data/guides/output/images/icons/callouts/10.png +0 -0
- data/guides/output/images/icons/callouts/11.png +0 -0
- data/guides/output/images/icons/callouts/12.png +0 -0
- data/guides/output/images/icons/callouts/13.png +0 -0
- data/guides/output/images/icons/callouts/14.png +0 -0
- data/guides/output/images/icons/callouts/15.png +0 -0
- data/guides/output/images/icons/callouts/2.png +0 -0
- data/guides/output/images/icons/callouts/3.png +0 -0
- data/guides/output/images/icons/callouts/4.png +0 -0
- data/guides/output/images/icons/callouts/5.png +0 -0
- data/guides/output/images/icons/callouts/6.png +0 -0
- data/guides/output/images/icons/callouts/7.png +0 -0
- data/guides/output/images/icons/callouts/8.png +0 -0
- data/guides/output/images/icons/callouts/9.png +0 -0
- data/guides/output/images/icons/caution.png +0 -0
- data/guides/output/images/icons/example.png +0 -0
- data/guides/output/images/icons/home.png +0 -0
- data/guides/output/images/icons/important.png +0 -0
- data/guides/output/images/icons/next.png +0 -0
- data/guides/output/images/icons/note.png +0 -0
- data/guides/output/images/icons/prev.png +0 -0
- data/guides/output/images/icons/tip.png +0 -0
- data/guides/output/images/icons/up.png +0 -0
- data/guides/output/images/icons/warning.png +0 -0
- data/guides/output/images/jaimeiniesta.jpg +0 -0
- data/guides/output/images/nav_arrow.gif +0 -0
- data/guides/output/images/polymorphic.png +0 -0
- data/guides/output/images/posts_index.png +0 -0
- data/guides/output/images/radar.png +0 -0
- data/guides/output/images/rails_guides_logo.gif +0 -0
- data/guides/output/images/rails_logo_remix.gif +0 -0
- data/guides/output/images/rails_welcome.png +0 -0
- data/guides/output/images/session_fixation.png +0 -0
- data/guides/output/images/tab_grey.gif +0 -0
- data/guides/output/images/tab_info.gif +0 -0
- data/guides/output/images/tab_note.gif +0 -0
- data/guides/output/images/tab_red.gif +0 -0
- data/guides/output/images/tab_yellow.gif +0 -0
- data/guides/output/images/tab_yellow.png +0 -0
- data/guides/output/images/validation_error_messages.png +0 -0
- data/guides/output/images/vijaydev.jpg +0 -0
- data/guides/output/index.html +300 -0
- data/guides/output/initialization.html +1087 -0
- data/guides/output/javascripts/guides.js +7 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
- data/guides/output/javascripts/syntaxhighlighter/shCore.js +17 -0
- data/guides/output/layout.html +312 -0
- data/guides/output/layouts_and_rendering.html +1257 -0
- data/guides/output/migrations.html +751 -0
- data/guides/output/nested_model_forms.html +350 -0
- data/guides/output/performance_testing.html +858 -0
- data/guides/output/plugins.html +590 -0
- data/guides/output/rails_application_templates.html +368 -0
- data/guides/output/rails_on_rack.html +408 -0
- data/guides/output/routing.html +1246 -0
- data/guides/output/ruby_on_rails_guides_guidelines.html +218 -0
- data/guides/output/security.html +968 -0
- data/guides/output/stylesheets/fixes.css +16 -0
- data/guides/output/stylesheets/main.css +445 -0
- data/guides/output/stylesheets/print.css +52 -0
- data/guides/output/stylesheets/reset.css +43 -0
- data/guides/output/stylesheets/style.css +13 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCore.css +226 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
- data/guides/output/testing.html +1182 -0
- data/guides/source/active_record_validations_callbacks.textile +3 -3
- data/guides/source/active_support_core_extensions.textile +2 -2
- data/guides/source/asset_pipeline.textile +7 -5
- data/guides/source/association_basics.textile +2 -4
- data/guides/source/command_line.textile +1 -1
- data/guides/source/configuring.textile +4 -2
- data/guides/source/contributing_to_ruby_on_rails.textile +6 -6
- data/guides/source/initialization.textile +2 -2
- data/guides/source/performance_testing.textile +1 -1
- data/guides/source/routing.textile +1 -1
- data/guides/source/security.textile +2 -2
- data/lib/rails/commands/server.rb +1 -1
- data/lib/rails/engine.rb +1 -1
- data/lib/rails/generators/app_base.rb +2 -1
- data/lib/rails/generators/base.rb +3 -3
- data/lib/rails/generators/rails/app/templates/gitignore +15 -5
- data/lib/rails/rack.rb +0 -1
- data/lib/rails/tasks/documentation.rake +7 -7
- data/lib/rails/tasks/misc.rake +0 -2
- data/lib/rails/test_unit/testing.rake +2 -0
- data/lib/rails/version.rb +2 -2
- metadata +495 -326
- data/CHANGELOG +0 -2371
- data/lib/rails/rack/content_length.rb +0 -38
@@ -0,0 +1,670 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
|
8
|
+
<title>Ruby on Rails Guides: Ruby on Rails 3.1 Release Notes</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
11
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
12
|
+
|
13
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
14
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
15
|
+
|
16
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
|
17
|
+
</head>
|
18
|
+
<body class="guide">
|
19
|
+
<div id="topNav">
|
20
|
+
<div class="wrapper">
|
21
|
+
<strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
|
22
|
+
<a href="http://rubyonrails.org/">Overview</a> |
|
23
|
+
<a href="http://rubyonrails.org/download">Download</a> |
|
24
|
+
<a href="http://rubyonrails.org/deploy">Deploy</a> |
|
25
|
+
<a href="https://github.com/rails/rails">Code</a> |
|
26
|
+
<a href="http://rubyonrails.org/screencasts">Screencasts</a> |
|
27
|
+
<a href="http://rubyonrails.org/documentation">Documentation</a> |
|
28
|
+
<a href="http://rubyonrails.org/ecosystem">Ecosystem</a> |
|
29
|
+
<a href="http://rubyonrails.org/community">Community</a> |
|
30
|
+
<a href="http://weblog.rubyonrails.org/">Blog</a>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
<div id="header">
|
34
|
+
<div class="wrapper clearfix">
|
35
|
+
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
|
36
|
+
<p class="hide"><a href="#mainCol">Skip navigation</a>.</p>
|
37
|
+
<ul class="nav">
|
38
|
+
<li><a href="index.html">Home</a></li>
|
39
|
+
<li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
|
40
|
+
<div id="guides" class="clearfix" style="display: none;">
|
41
|
+
<hr />
|
42
|
+
<dl class="L">
|
43
|
+
<dt>Start Here</dt>
|
44
|
+
<dd><a href="getting_started.html">Getting Started with Rails</a></dd>
|
45
|
+
<dt>Models</dt>
|
46
|
+
<dd><a href="migrations.html">Rails Database Migrations</a></dd>
|
47
|
+
<dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
|
48
|
+
<dd><a href="association_basics.html">Active Record Associations</a></dd>
|
49
|
+
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
|
50
|
+
<dt>Views</dt>
|
51
|
+
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
|
52
|
+
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
|
53
|
+
<dt>Controllers</dt>
|
54
|
+
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
|
55
|
+
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
|
56
|
+
</dl>
|
57
|
+
<dl class="R">
|
58
|
+
<dt>Digging Deeper</dt>
|
59
|
+
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
|
60
|
+
<dd><a href="i18n.html">Rails Internationalization API</a></dd>
|
61
|
+
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
|
62
|
+
<dd><a href="testing.html">Testing Rails Applications</a></dd>
|
63
|
+
<dd><a href="security.html">Securing Rails Applications</a></dd>
|
64
|
+
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
|
65
|
+
<dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
|
66
|
+
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
|
67
|
+
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
|
68
|
+
<dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
|
69
|
+
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
|
70
|
+
|
71
|
+
<dt>Extending Rails</dt>
|
72
|
+
<dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
|
73
|
+
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
|
74
|
+
<dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
|
75
|
+
|
76
|
+
<dt>Contributing to Ruby on Rails</dt>
|
77
|
+
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
|
78
|
+
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
79
|
+
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
80
|
+
|
81
|
+
<dt>Release Notes</dt>
|
82
|
+
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
|
83
|
+
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
84
|
+
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
|
85
|
+
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
|
86
|
+
</dl>
|
87
|
+
</div>
|
88
|
+
</li>
|
89
|
+
<li><a href="contributing_to_ruby_on_rails.html">Contribute</a></li>
|
90
|
+
<li><a href="credits.html">Credits</a></li>
|
91
|
+
</ul>
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
<hr class="hide" />
|
95
|
+
|
96
|
+
<div id="feature">
|
97
|
+
<div class="wrapper">
|
98
|
+
<h2>Ruby on Rails 3.1 Release Notes</h2>
|
99
|
+
<p>Highlights in Rails 3.1:</p>
|
100
|
+
<ul>
|
101
|
+
<li>Streaming</li>
|
102
|
+
<li>Reversible Migrations</li>
|
103
|
+
<li>Assets Pipeline</li>
|
104
|
+
<li>jQuery as the default JavaScript library</li>
|
105
|
+
</ul>
|
106
|
+
<p>This release notes cover the major changes, but don’t include every little bug fix and change. If you want to see everything, check out the <a href="https://github.com/rails/rails/commits/master">list of commits</a> in the main Rails repository on GitHub.</p>
|
107
|
+
|
108
|
+
<div id="subCol">
|
109
|
+
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
|
110
|
+
<ol class="chapters">
|
111
|
+
<li><a href="#upgrading-to-rails-3-1">Upgrading to Rails 3.1</a><ul><li><a href="#rails-3-1-requires-at-least-ruby-1-8-7">Rails 3.1 requires at least Ruby 1.8.7</a></li></ul></li><li><a href="#creating-a-rails-3-1-application">Creating a Rails 3.1 application</a><ul><li><a href="#vendoring-gems">Vendoring Gems</a></li> <li><a href="#living-on-the-edge">Living on the Edge</a></li></ul></li><li><a href="#rails-architectural-changes">Rails Architectural Changes</a><ul><li><a href="#assets-pipeline">Assets Pipeline</a></li> <li><a href="#http-streaming"><span class="caps">HTTP</span> Streaming</a></li> <li><a href="#default-js-library-is-now-jquery">Default JS library is now jQuery</a></li> <li><a href="#identity-map">Identity Map</a></li></ul></li><li><a href="#railties">Railties</a></li><li><a href="#action-pack">Action Pack</a><ul><li><a href="#action-controller">Action Controller</a></li> <li><a href="#action-dispatch">Action Dispatch</a></li> <li><a href="#action-view">Action View</a></li></ul></li><li><a href="#active-record">Active Record</a></li><li><a href="#active-model">Active Model</a></li><li><a href="#active-resource">Active Resource</a></li><li><a href="#active-support">Active Support</a></li><li><a href="#credits">Credits</a></li></ol></div>
|
112
|
+
</div>
|
113
|
+
</div>
|
114
|
+
|
115
|
+
<div id="container">
|
116
|
+
<div class="wrapper">
|
117
|
+
<div id="mainCol">
|
118
|
+
<h3 id="upgrading-to-rails-3-1">1 Upgrading to Rails 3.1</h3>
|
119
|
+
<p>If you’re upgrading an existing application, it’s a great idea to have good test coverage before going in. You should also first upgrade to Rails 3 in case you haven’t and make sure your application still runs as expected before attempting to update to Rails 3.1. Then take heed of the following changes:</p>
|
120
|
+
<h4 id="rails-3-1-requires-at-least-ruby-1-8-7">1.1 Rails 3.1 requires at least Ruby 1.8.7</h4>
|
121
|
+
<p>Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.1 is also compatible with Ruby 1.9.2.</p>
|
122
|
+
<div class="info"><p>Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing.</p></div>
|
123
|
+
<h3 id="creating-a-rails-3-1-application">2 Creating a Rails 3.1 application</h3>
|
124
|
+
<div class="code_container">
|
125
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
126
|
+
# You should have the 'rails' rubygem installed
|
127
|
+
$ rails new myapp
|
128
|
+
$ cd myapp
|
129
|
+
</pre>
|
130
|
+
</div>
|
131
|
+
<h4 id="vendoring-gems">2.1 Vendoring Gems</h4>
|
132
|
+
<p>Rails now uses a <tt>Gemfile</tt> in the application root to determine the gems you require for your application to start. This <tt>Gemfile</tt> is processed by the <a href="https://github.com/carlhuda/bundler">Bundler</a> gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn’t depend on the system gems.</p>
|
133
|
+
<p>More information: – <a href="http://gembundler.com">bundler homepage</a></p>
|
134
|
+
<h4 id="living-on-the-edge">2.2 Living on the Edge</h4>
|
135
|
+
<p><tt>Bundler</tt> and <tt>Gemfile</tt> makes freezing your Rails application easy as pie with the new dedicated <tt>bundle</tt> command. If you want to bundle straight from the Git repository, you can pass the <tt>--edge</tt> flag:</p>
|
136
|
+
<div class="code_container">
|
137
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
138
|
+
$ rails new myapp --edge
|
139
|
+
</pre>
|
140
|
+
</div>
|
141
|
+
<p>If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the <tt>--dev</tt> flag:</p>
|
142
|
+
<div class="code_container">
|
143
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
144
|
+
$ ruby /path/to/rails/bin/rails new myapp --dev
|
145
|
+
</pre>
|
146
|
+
</div>
|
147
|
+
<h3 id="rails-architectural-changes">3 Rails Architectural Changes</h3>
|
148
|
+
<h4 id="assets-pipeline">3.1 Assets Pipeline</h4>
|
149
|
+
<p>The major change in Rails 3.1 is the Assets Pipeline. It makes <span class="caps">CSS</span> and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines.</p>
|
150
|
+
<p>The assets pipeline is powered by <a href="https://github.com/sstephenson/sprockets">Sprockets</a> and is covered in the <a href="asset_pipeline.html">Asset Pipeline</a> guide.</p>
|
151
|
+
<h4 id="http-streaming">3.2 <span class="caps">HTTP</span> Streaming</h4>
|
152
|
+
<p><span class="caps">HTTP</span> Streaming is another change that is new in Rails 3.1. This lets the browser download your stylesheets and JavaScript files while the server is still generating the response. This requires Ruby 1.9.2, is opt-in and requires support from the web server as well, but the popular combo of nginx and unicorn is ready to take advantage of it.</p>
|
153
|
+
<h4 id="default-js-library-is-now-jquery">3.3 Default JS library is now jQuery</h4>
|
154
|
+
<p>jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it’s simple to switch.</p>
|
155
|
+
<div class="code_container">
|
156
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
157
|
+
$ rails new myapp -j prototype
|
158
|
+
</pre>
|
159
|
+
</div>
|
160
|
+
<h4 id="identity-map">3.4 Identity Map</h4>
|
161
|
+
<p>Active Record has an Identity Map in Rails 3.1. An identity map keeps previously instantiated records and returns the object associated with the record if accessed again. The identity map is created on a per-request basis and is flushed at request completion.</p>
|
162
|
+
<p>Rails 3.1 comes with the identity map turned off by default.</p>
|
163
|
+
<h3 id="railties">4 Railties</h3>
|
164
|
+
<ul>
|
165
|
+
<li>jQuery is the new default JavaScript library.</li>
|
166
|
+
</ul>
|
167
|
+
<ul>
|
168
|
+
<li>jQuery and Prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems.</li>
|
169
|
+
</ul>
|
170
|
+
<ul>
|
171
|
+
<li>The application generator accepts an option <tt>-j</tt> which can be an arbitrary string. If passed “foo”, the gem “foo-rails” is added to the <tt>Gemfile</tt>, and the application JavaScript manifest requires “foo” and “foo_ujs”. Currently only “prototype-rails” and “jquery-rails” exist and provide those files via the asset pipeline.</li>
|
172
|
+
</ul>
|
173
|
+
<ul>
|
174
|
+
<li>Generating an application or a plugin runs <tt>bundle install</tt> unless <tt>--skip-gemfile</tt> or <tt>--skip-bundle</tt> is specified.</li>
|
175
|
+
</ul>
|
176
|
+
<ul>
|
177
|
+
<li>The controller and resource generators will now automatically produce asset stubs (this can be turned off with <tt>--skip-assets</tt>). These stubs will use CoffeeScript and Sass, if those libraries are available.</li>
|
178
|
+
</ul>
|
179
|
+
<ul>
|
180
|
+
<li>Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, <tt>--old-style-hash</tt> can be passed.</li>
|
181
|
+
</ul>
|
182
|
+
<ul>
|
183
|
+
<li>Scaffold controller generator creates format block for <span class="caps">JSON</span> instead of <span class="caps">XML</span>.</li>
|
184
|
+
</ul>
|
185
|
+
<ul>
|
186
|
+
<li>Active Record logging is directed to <span class="caps">STDOUT</span> and shown inline in the console.</li>
|
187
|
+
</ul>
|
188
|
+
<ul>
|
189
|
+
<li>Added <tt>config.force_ssl</tt> configuration which loads <tt>Rack::<span class="caps">SSL</span></tt> middleware and force all requests to be under <span class="caps">HTTPS</span> protocol.</li>
|
190
|
+
</ul>
|
191
|
+
<ul>
|
192
|
+
<li>Added <tt>rails plugin new</tt> command which generates a Rails plugin with gemspec, tests and a dummy application for testing.</li>
|
193
|
+
</ul>
|
194
|
+
<ul>
|
195
|
+
<li>Added <tt>Rack::Etag</tt> and <tt>Rack::ConditionalGet</tt> to the default middleware stack.</li>
|
196
|
+
</ul>
|
197
|
+
<ul>
|
198
|
+
<li>Added <tt>Rack::Cache</tt> to the default middleware stack.</li>
|
199
|
+
</ul>
|
200
|
+
<ul>
|
201
|
+
<li>Engines received a major update – You can mount them at any path, enable assets, run generators etc.</li>
|
202
|
+
</ul>
|
203
|
+
<h3 id="action-pack">5 Action Pack</h3>
|
204
|
+
<h4 id="action-controller">5.1 Action Controller</h4>
|
205
|
+
<ul>
|
206
|
+
<li>A warning is given out if the <span class="caps">CSRF</span> token authenticity cannot be verified.</li>
|
207
|
+
</ul>
|
208
|
+
<ul>
|
209
|
+
<li>Specify <tt>force_ssl</tt> in a controller to force the browser to transfer data via <span class="caps">HTTPS</span> protocol on that particular controller. To limit to specific actions, <tt>:only</tt> or <tt>:except</tt> can be used.</li>
|
210
|
+
</ul>
|
211
|
+
<ul>
|
212
|
+
<li>Sensitive query string parameters specified in <tt>config.filter_parameters</tt> will now be filtered out from the request paths in the log.</li>
|
213
|
+
</ul>
|
214
|
+
<ul>
|
215
|
+
<li><span class="caps">URL</span> parameters which return <tt>nil</tt> for <tt>to_param</tt> are now removed from the query string.</li>
|
216
|
+
</ul>
|
217
|
+
<ul>
|
218
|
+
<li>Added <tt>ActionController::ParamsWrapper</tt> to wrap parameters into a nested hash, and will be turned on for <span class="caps">JSON</span> request in new applications by default. This can be customized in <tt>config/initializers/wrap_parameters.rb</tt>.</li>
|
219
|
+
</ul>
|
220
|
+
<ul>
|
221
|
+
<li>Added <tt>config.action_controller.include_all_helpers</tt>. By default <tt>helper :all</tt> is done in <tt>ActionController::Base</tt>, which includes all the helpers by default. Setting <tt>include_all_helpers</tt> to <tt>false</tt> will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).</li>
|
222
|
+
</ul>
|
223
|
+
<ul>
|
224
|
+
<li><tt>url_for</tt> and named url helpers now accept <tt>:subdomain</tt> and <tt>:domain</tt> as options.</li>
|
225
|
+
</ul>
|
226
|
+
<ul>
|
227
|
+
<li>Added <tt>Base.http_basic_authenticate_with</tt> to do simple http basic authentication with a single class method call.</li>
|
228
|
+
</ul>
|
229
|
+
<div class="code_container">
|
230
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
231
|
+
class PostsController < ApplicationController
|
232
|
+
USER_NAME, PASSWORD = "dhh", "secret"
|
233
|
+
|
234
|
+
before_filter :authenticate, :except => [ :index ]
|
235
|
+
|
236
|
+
def index
|
237
|
+
render :text => "Everyone can see me!"
|
238
|
+
end
|
239
|
+
|
240
|
+
def edit
|
241
|
+
render :text => "I'm only accessible if you know the password"
|
242
|
+
end
|
243
|
+
|
244
|
+
private
|
245
|
+
def authenticate
|
246
|
+
authenticate_or_request_with_http_basic do |user_name, password|
|
247
|
+
user_name == USER_NAME && password == PASSWORD
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
</pre>
|
252
|
+
</div>
|
253
|
+
<p>..can now be written as</p>
|
254
|
+
<div class="code_container">
|
255
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
256
|
+
class PostsController < ApplicationController
|
257
|
+
http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
|
258
|
+
|
259
|
+
def index
|
260
|
+
render :text => "Everyone can see me!"
|
261
|
+
end
|
262
|
+
|
263
|
+
def edit
|
264
|
+
render :text => "I'm only accessible if you know the password"
|
265
|
+
end
|
266
|
+
end
|
267
|
+
</pre>
|
268
|
+
</div>
|
269
|
+
<ul>
|
270
|
+
<li>Added streaming support, you can enable it with:</li>
|
271
|
+
</ul>
|
272
|
+
<div class="code_container">
|
273
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
274
|
+
class PostsController < ActionController::Base
|
275
|
+
stream
|
276
|
+
end
|
277
|
+
</pre>
|
278
|
+
</div>
|
279
|
+
<p>You can restrict it to some actions by using <tt>:only</tt> or <tt>:except</tt>. Please read the docs at <a href="http://api.rubyonrails.org/classes/ActionController/Streaming.html"><tt>ActionController::Streaming</tt></a> for more information.</p>
|
280
|
+
<ul>
|
281
|
+
<li>The redirect route method now also accepts a hash of options which will only change the parts of the url in question, or an object which responds to call, allowing for redirects to be reused.</li>
|
282
|
+
</ul>
|
283
|
+
<h4 id="action-dispatch">5.2 Action Dispatch</h4>
|
284
|
+
<ul>
|
285
|
+
<li><tt>config.action_dispatch.x_sendfile_header</tt> now defaults to <tt>nil</tt> and <tt>config/environments/production.rb</tt> doesn’t set any particular value for it. This allows servers to set it through <tt>X-Sendfile-Type</tt>.</li>
|
286
|
+
</ul>
|
287
|
+
<ul>
|
288
|
+
<li><tt>ActionDispatch::MiddlewareStack</tt> now uses composition over inheritance and is no longer an array.</li>
|
289
|
+
</ul>
|
290
|
+
<ul>
|
291
|
+
<li>Added <tt>ActionDispatch::Request.ignore_accept_header</tt> to ignore accept headers.</li>
|
292
|
+
</ul>
|
293
|
+
<ul>
|
294
|
+
<li>Added <tt>Rack::Cache</tt> to the default stack.</li>
|
295
|
+
</ul>
|
296
|
+
<ul>
|
297
|
+
<li>Moved etag responsibility from <tt>ActionDispatch::Response</tt> to the middleware stack.</li>
|
298
|
+
</ul>
|
299
|
+
<ul>
|
300
|
+
<li>Rely on <tt>Rack::Session</tt> stores <span class="caps">API</span> for more compatibility across the Ruby world. This is backwards incompatible since <tt>Rack::Session</tt> expects <tt>#get_session</tt> to accept four arguments and requires <tt>#destroy_session</tt> instead of simply <tt>#destroy</tt>.</li>
|
301
|
+
</ul>
|
302
|
+
<ul>
|
303
|
+
<li>Template lookup now searches further up in the inheritance chain.</li>
|
304
|
+
</ul>
|
305
|
+
<h4 id="action-view">5.3 Action View</h4>
|
306
|
+
<ul>
|
307
|
+
<li>Added an <tt>:authenticity_token</tt> option to <tt>form_tag</tt> for custom handling or to omit the token by passing <tt>:authenticity_token => false</tt>.</li>
|
308
|
+
</ul>
|
309
|
+
<ul>
|
310
|
+
<li>Created <tt>ActionView::Renderer</tt> and specified an <span class="caps">API</span> for <tt>ActionView::Context</tt>.</li>
|
311
|
+
</ul>
|
312
|
+
<ul>
|
313
|
+
<li>In place <tt>SafeBuffer</tt> mutation is prohibited in Rails 3.1.</li>
|
314
|
+
</ul>
|
315
|
+
<ul>
|
316
|
+
<li>Added HTML5 <tt>button_tag</tt> helper.</li>
|
317
|
+
</ul>
|
318
|
+
<ul>
|
319
|
+
<li><tt>file_field</tt> automatically adds <tt>:multipart => true</tt> to the enclosing form.</li>
|
320
|
+
</ul>
|
321
|
+
<ul>
|
322
|
+
<li>Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a <tt>:data</tt> hash of options:</li>
|
323
|
+
</ul>
|
324
|
+
<div class="code_container">
|
325
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
326
|
+
tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)})
|
327
|
+
# => <div data-name="Stephen" data-city-state="[&quot;Chicago&quot;,&quot;IL&quot;]" />
|
328
|
+
</pre>
|
329
|
+
</div>
|
330
|
+
<p>Keys are dasherized. Values are <span class="caps">JSON</span>-encoded, except for strings and symbols.</p>
|
331
|
+
<ul>
|
332
|
+
<li><tt>csrf_meta_tag</tt> is renamed to <tt>csrf_meta_tags</tt> and aliases <tt>csrf_meta_tag</tt> for backwards compatibility.</li>
|
333
|
+
</ul>
|
334
|
+
<ul>
|
335
|
+
<li>The old template handler <span class="caps">API</span> is deprecated and the new <span class="caps">API</span> simply requires a template handler to respond to call.</li>
|
336
|
+
</ul>
|
337
|
+
<ul>
|
338
|
+
<li>rhtml and rxml are finally removed as template handlers.</li>
|
339
|
+
</ul>
|
340
|
+
<ul>
|
341
|
+
<li><tt>config.action_view.cache_template_loading</tt> is brought back which allows to decide whether templates should be cached or not.</li>
|
342
|
+
</ul>
|
343
|
+
<ul>
|
344
|
+
<li>The submit form helper does not generate an id “object_name_id” anymore.</li>
|
345
|
+
</ul>
|
346
|
+
<ul>
|
347
|
+
<li>Allows <tt>FormHelper#form_for</tt> to specify the <tt>:method</tt> as a direct option instead of through the <tt>:html</tt> hash. <tt>form_for(@post, remote: true, method: :delete)</tt> instead of <tt>form_for(@post, remote: true, html: { method: :delete })</tt>.</li>
|
348
|
+
</ul>
|
349
|
+
<ul>
|
350
|
+
<li>Provided <tt>JavaScriptHelper#j()</tt> as an alias for <tt>JavaScriptHelper#escape_javascript()</tt>. This supersedes the <tt>Object#j()</tt> method that the <span class="caps">JSON</span> gem adds within templates using the JavaScriptHelper.</li>
|
351
|
+
</ul>
|
352
|
+
<ul>
|
353
|
+
<li>Allows AM/PM format in datetime selectors.</li>
|
354
|
+
</ul>
|
355
|
+
<ul>
|
356
|
+
<li><tt>auto_link</tt> has been removed from Rails and extracted into the <a href="https://github.com/tenderlove/rails_autolink">rails_autolink gem</a></li>
|
357
|
+
</ul>
|
358
|
+
<h3 id="active-record">6 Active Record</h3>
|
359
|
+
<ul>
|
360
|
+
<li>Added a class method <tt>pluralize_table_names</tt> to singularize/pluralize table names of individual models. Previously this could only be set globally for all models through <tt>ActiveRecord::Base.pluralize_table_names</tt>.
|
361
|
+
<div class="code_container">
|
362
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
363
|
+
class User < ActiveRecord::Base
|
364
|
+
self.pluralize_table_names = false
|
365
|
+
end
|
366
|
+
</pre>
|
367
|
+
</div>
|
368
|
+
</li>
|
369
|
+
</ul>
|
370
|
+
<ul>
|
371
|
+
<li>Added block setting of attributes to singular associations. The block will get called after the instance is initialized.</li>
|
372
|
+
</ul>
|
373
|
+
<div class="code_container">
|
374
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
375
|
+
class User < ActiveRecord::Base
|
376
|
+
has_one :account
|
377
|
+
end
|
378
|
+
|
379
|
+
user.build_account{ |a| a.credit_limit = 100.0 }
|
380
|
+
</pre>
|
381
|
+
</div>
|
382
|
+
<ul>
|
383
|
+
<li>Added <tt>ActiveRecord::Base.attribute_names</tt> to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist.</li>
|
384
|
+
</ul>
|
385
|
+
<ul>
|
386
|
+
<li><span class="caps">CSV</span> Fixtures are deprecated and support will be removed in Rails 3.2.0.</li>
|
387
|
+
</ul>
|
388
|
+
<ul>
|
389
|
+
<li><tt>ActiveRecord#new</tt>, <tt>ActiveRecord#create</tt> and <tt>ActiveRecord#update_attributes</tt> all accept a second hash as an option that allows you to specify which role to consider when assigning attributes. This is built on top of Active Model’s new mass assignment capabilities:</li>
|
390
|
+
</ul>
|
391
|
+
<div class="code_container">
|
392
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
393
|
+
class Post < ActiveRecord::Base
|
394
|
+
attr_accessible :title
|
395
|
+
attr_accessible :title, :published_at, :as => :admin
|
396
|
+
end
|
397
|
+
|
398
|
+
Post.new(params[:post], :as => :admin)
|
399
|
+
</pre>
|
400
|
+
</div>
|
401
|
+
<ul>
|
402
|
+
<li><tt>default_scope</tt> can now take a block, lambda, or any other object which responds to call for lazy evaluation.</li>
|
403
|
+
</ul>
|
404
|
+
<ul>
|
405
|
+
<li>Default scopes are now evaluated at the latest possible moment, to avoid problems where scopes would be created which would implicitly contain the default scope, which would then be impossible to get rid of via Model.unscoped.</li>
|
406
|
+
</ul>
|
407
|
+
<ul>
|
408
|
+
<li>PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.</li>
|
409
|
+
</ul>
|
410
|
+
<ul>
|
411
|
+
<li><tt>ConnectionManagement</tt> middleware is changed to clean up the connection pool after the rack body has been flushed.</li>
|
412
|
+
</ul>
|
413
|
+
<ul>
|
414
|
+
<li>Added an <tt>update_column</tt> method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use <tt>update_attributes</tt> or <tt>update_attribute</tt> unless you are sure you do not want to execute any callback, including the modification of the <tt>updated_at</tt> column. It should not be called on new records.</li>
|
415
|
+
</ul>
|
416
|
+
<ul>
|
417
|
+
<li>Associations with a <tt>:through</tt> option can now use any association as the through or source association, including other associations which have a <tt>:through</tt> option and <tt>has_and_belongs_to_many</tt> associations.</li>
|
418
|
+
</ul>
|
419
|
+
<ul>
|
420
|
+
<li>The configuration for the current database connection is now accessible via <tt>ActiveRecord::Base.connection_config</tt>.</li>
|
421
|
+
</ul>
|
422
|
+
<ul>
|
423
|
+
<li>limits and offsets are removed from <span class="caps">COUNT</span> queries unless both are supplied.
|
424
|
+
<div class="code_container">
|
425
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
426
|
+
People.limit(1).count # => 'SELECT COUNT(*) FROM people'
|
427
|
+
People.offset(1).count # => 'SELECT COUNT(*) FROM people'
|
428
|
+
People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
|
429
|
+
</pre>
|
430
|
+
</div>
|
431
|
+
</li>
|
432
|
+
</ul>
|
433
|
+
<ul>
|
434
|
+
<li><tt>ActiveRecord::Associations::AssociationProxy</tt> has been split. There is now an <tt>Association</tt> class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called <tt>CollectionProxy</tt>, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings.</li>
|
435
|
+
</ul>
|
436
|
+
<ul>
|
437
|
+
<li>Singular associations (<tt>has_one</tt>, <tt>belongs_to</tt>) no longer have a proxy and simply returns the associated record or <tt>nil</tt>. This means that you should not use undocumented methods such as <tt>bob.mother.create</tt> – use <tt>bob.create_mother</tt> instead.</li>
|
438
|
+
</ul>
|
439
|
+
<ul>
|
440
|
+
<li>Support the <tt>:dependent</tt> option on <tt>has_many :through</tt> associations. For historical and practical reasons, <tt>:delete_all</tt> is the default deletion strategy employed by <tt>association.delete(*records)</tt>, despite the fact that the default strategy is <tt>:nullify</tt> for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.</li>
|
441
|
+
</ul>
|
442
|
+
<ul>
|
443
|
+
<li>The behavior of <tt>association.destroy</tt> for <tt>has_and_belongs_to_many</tt> and <tt>has_many :through</tt> is changed. From now on, ‘destroy’ or ‘delete’ on an association will be taken to mean ‘get rid of the link’, not (necessarily) ‘get rid of the associated records’.</li>
|
444
|
+
</ul>
|
445
|
+
<ul>
|
446
|
+
<li>Previously, <tt>has_and_belongs_to_many.destroy(*records)</tt> would destroy the records themselves. It would not delete any records in the join table. Now, it deletes the records in the join table.</li>
|
447
|
+
</ul>
|
448
|
+
<ul>
|
449
|
+
<li>Previously, <tt>has_many_through.destroy(*records)</tt> would destroy the records themselves, and the records in the join table. [Note: This has not always been the case; previous version of Rails only deleted the records themselves.] Now, it destroys only the records in the join table.</li>
|
450
|
+
</ul>
|
451
|
+
<ul>
|
452
|
+
<li>Note that this change is backwards-incompatible to an extent, but there is unfortunately no way to ‘deprecate’ it before changing it. The change is being made in order to have consistency as to the meaning of ‘destroy’ or ‘delete’ across the different types of associations. If you wish to destroy the records themselves, you can do <tt>records.association.each(&:destroy)</tt>.</li>
|
453
|
+
</ul>
|
454
|
+
<ul>
|
455
|
+
<li>Add <tt>:bulk => true</tt> option to <tt>change_table</tt> to make all the schema changes defined in a block using a single <span class="caps">ALTER</span> statement.</li>
|
456
|
+
</ul>
|
457
|
+
<div class="code_container">
|
458
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
459
|
+
change_table(:users, :bulk => true) do |t|
|
460
|
+
t.string :company_name
|
461
|
+
t.change :birthdate, :datetime
|
462
|
+
end
|
463
|
+
</pre>
|
464
|
+
</div>
|
465
|
+
<ul>
|
466
|
+
<li>Removed support for accessing attributes on a <tt>has_and_belongs_to_many</tt> join table. <tt>has_many :through</tt> needs to be used.</li>
|
467
|
+
</ul>
|
468
|
+
<ul>
|
469
|
+
<li>Added a <tt>create_association!</tt> method for <tt>has_one</tt> and <tt>belongs_to</tt> associations.</li>
|
470
|
+
</ul>
|
471
|
+
<ul>
|
472
|
+
<li>Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations. To use reversible migrations, just define the <tt>change</tt> method.
|
473
|
+
<div class="code_container">
|
474
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
475
|
+
class MyMigration < ActiveRecord::Migration
|
476
|
+
def change
|
477
|
+
create_table(:horses) do |t|
|
478
|
+
t.column :content, :text
|
479
|
+
t.column :remind_at, :datetime
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
</pre>
|
484
|
+
</div>
|
485
|
+
</li>
|
486
|
+
</ul>
|
487
|
+
<ul>
|
488
|
+
<li>Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define <tt>up</tt> and <tt>down</tt> in your migration. If you define something in change that cannot be reversed, an <tt>IrreversibleMigration</tt> exception will be raised when going down.</li>
|
489
|
+
</ul>
|
490
|
+
<ul>
|
491
|
+
<li>Migrations now use instance methods rather than class methods:
|
492
|
+
<div class="code_container">
|
493
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
494
|
+
class FooMigration < ActiveRecord::Migration
|
495
|
+
def up # Not self.up
|
496
|
+
...
|
497
|
+
end
|
498
|
+
end
|
499
|
+
</pre>
|
500
|
+
</div>
|
501
|
+
</li>
|
502
|
+
</ul>
|
503
|
+
<ul>
|
504
|
+
<li>Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration’s <tt>change</tt> method instead of the ordinary <tt>up</tt> and <tt>down</tt> methods.</li>
|
505
|
+
</ul>
|
506
|
+
<ul>
|
507
|
+
<li>Removed support for interpolating string <span class="caps">SQL</span> conditions on associations. Instead, a proc should be used.</li>
|
508
|
+
</ul>
|
509
|
+
<div class="code_container">
|
510
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
511
|
+
has_many :things, :conditions => 'foo = #{bar}' # before
|
512
|
+
has_many :things, :conditions => proc { "foo = #{bar}" } # after
|
513
|
+
</pre>
|
514
|
+
</div>
|
515
|
+
<p>Inside the proc, <tt>self</tt> is the object which is the owner of the association, unless you are eager loading the association, in which case <tt>self</tt> is the class which the association is within.</p>
|
516
|
+
<p>You can have any “normal” conditions inside the proc, so the following will work too:</p>
|
517
|
+
<div class="code_container">
|
518
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
519
|
+
has_many :things, :conditions => proc { ["foo = ?", bar] }
|
520
|
+
</pre>
|
521
|
+
</div>
|
522
|
+
<ul>
|
523
|
+
<li>Previously <tt>:insert_sql</tt> and <tt>:delete_sql</tt> on <tt>has_and_belongs_to_many</tt> association allowed you to call ‘record’ to get the record being inserted or deleted. This is now passed as an argument to the proc.</li>
|
524
|
+
</ul>
|
525
|
+
<ul>
|
526
|
+
<li>Added <tt>ActiveRecord::Base#has_secure_password</tt> (via <tt>ActiveModel::SecurePassword</tt>) to encapsulate dead-simple password usage with BCrypt encryption and salting.</li>
|
527
|
+
</ul>
|
528
|
+
<div class="code_container">
|
529
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
530
|
+
# Schema: User(name:string, password_digest:string, password_salt:string)
|
531
|
+
class User < ActiveRecord::Base
|
532
|
+
has_secure_password
|
533
|
+
end
|
534
|
+
</pre>
|
535
|
+
</div>
|
536
|
+
<ul>
|
537
|
+
<li>When a model is generated <tt>add_index</tt> is added by default for <tt>belongs_to</tt> or <tt>references</tt> columns.</li>
|
538
|
+
</ul>
|
539
|
+
<ul>
|
540
|
+
<li>Setting the id of a <tt>belongs_to</tt> object will update the reference to the object.</li>
|
541
|
+
</ul>
|
542
|
+
<ul>
|
543
|
+
<li><tt>ActiveRecord::Base#dup</tt> and <tt>ActiveRecord::Base#clone</tt> semantics have changed to closer match normal Ruby dup and clone semantics.</li>
|
544
|
+
</ul>
|
545
|
+
<ul>
|
546
|
+
<li>Calling <tt>ActiveRecord::Base#clone</tt> will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called.</li>
|
547
|
+
</ul>
|
548
|
+
<ul>
|
549
|
+
<li>Calling <tt>ActiveRecord::Base#dup</tt> will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return <tt>true</tt> for <tt>new_record?</tt>, have a <tt>nil</tt> id field, and is saveable.</li>
|
550
|
+
</ul>
|
551
|
+
<ul>
|
552
|
+
<li>The query cache now works with prepared statements. No changes in the applications are required.</li>
|
553
|
+
</ul>
|
554
|
+
<h3 id="active-model">7 Active Model</h3>
|
555
|
+
<ul>
|
556
|
+
<li><tt>attr_accessible</tt> accepts an option <tt>:as</tt> to specify a role.</li>
|
557
|
+
</ul>
|
558
|
+
<ul>
|
559
|
+
<li><tt>InclusionValidator</tt>, <tt>ExclusionValidator</tt>, and <tt>FormatValidator</tt> now accepts an option which can be a proc, a lambda, or anything that respond to <tt>call</tt>. This option will be called with the current record as an argument and returns an object which respond to <tt>include?</tt> for <tt>InclusionValidator</tt> and <tt>ExclusionValidator</tt>, and returns a regular expression object for <tt>FormatValidator</tt>.</li>
|
560
|
+
</ul>
|
561
|
+
<ul>
|
562
|
+
<li>Added <tt>ActiveModel::SecurePassword</tt> to encapsulate dead-simple password usage with BCrypt encryption and salting.</li>
|
563
|
+
</ul>
|
564
|
+
<ul>
|
565
|
+
<li><tt>ActiveModel::AttributeMethods</tt> allows attributes to be defined on demand.</li>
|
566
|
+
</ul>
|
567
|
+
<ul>
|
568
|
+
<li>Added support for selectively enabling and disabling observers.</li>
|
569
|
+
</ul>
|
570
|
+
<ul>
|
571
|
+
<li>Alternate <tt>I18n</tt> namespace lookup is no longer supported.</li>
|
572
|
+
</ul>
|
573
|
+
<h3 id="active-resource">8 Active Resource</h3>
|
574
|
+
<ul>
|
575
|
+
<li>The default format has been changed to <span class="caps">JSON</span> for all requests. If you want to continue to use <span class="caps">XML</span> you will need to set <tt>self.format = :xml</tt> in the class. For example,</li>
|
576
|
+
</ul>
|
577
|
+
<div class="code_container">
|
578
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
579
|
+
class User < ActiveResource::Base
|
580
|
+
self.format = :xml
|
581
|
+
end
|
582
|
+
</pre>
|
583
|
+
</div>
|
584
|
+
<h3 id="active-support">9 Active Support</h3>
|
585
|
+
<ul>
|
586
|
+
<li><tt>ActiveSupport::Dependencies</tt> now raises <tt>NameError</tt> if it finds an existing constant in <tt>load_missing_constant</tt>.</li>
|
587
|
+
</ul>
|
588
|
+
<ul>
|
589
|
+
<li>Added a new reporting method <tt>Kernel#quietly</tt> which silences both <tt>STDOUT</tt> and <tt>STDERR</tt>.</li>
|
590
|
+
</ul>
|
591
|
+
<ul>
|
592
|
+
<li>Added <tt>String#inquiry</tt> as a convenience method for turning a String into a <tt>StringInquirer</tt> object.</li>
|
593
|
+
</ul>
|
594
|
+
<ul>
|
595
|
+
<li>Added <tt>Object#in?</tt> to test if an object is included in another object.</li>
|
596
|
+
</ul>
|
597
|
+
<ul>
|
598
|
+
<li><tt>LocalCache</tt> strategy is now a real middleware class and no longer an anonymous class.</li>
|
599
|
+
</ul>
|
600
|
+
<ul>
|
601
|
+
<li><tt>ActiveSupport::Dependencies::ClassCache</tt> class has been introduced for holding references to reloadable classes.</li>
|
602
|
+
</ul>
|
603
|
+
<ul>
|
604
|
+
<li><tt>ActiveSupport::Dependencies::Reference</tt> has been refactored to take direct advantage of the new <tt>ClassCache</tt>.</li>
|
605
|
+
</ul>
|
606
|
+
<ul>
|
607
|
+
<li>Backports <tt>Range#cover?</tt> as an alias for <tt>Range#include?</tt> in Ruby 1.8.</li>
|
608
|
+
</ul>
|
609
|
+
<ul>
|
610
|
+
<li>Added <tt>weeks_ago</tt> and <tt>prev_week</tt> to Date/DateTime/Time.</li>
|
611
|
+
</ul>
|
612
|
+
<ul>
|
613
|
+
<li>Added <tt>before_remove_const</tt> callback to <tt>ActiveSupport::Dependencies.remove_unloadable_constants!</tt>.</li>
|
614
|
+
</ul>
|
615
|
+
<p>Deprecations:</p>
|
616
|
+
<ul>
|
617
|
+
<li><tt>ActiveSupport::SecureRandom</tt> is deprecated in favor of <tt>SecureRandom</tt> from the Ruby standard library.</li>
|
618
|
+
</ul>
|
619
|
+
<h3 id="credits">10 Credits</h3>
|
620
|
+
<p>See the <a href="http://contributors.rubyonrails.org/">full list of contributors to Rails</a> for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.</p>
|
621
|
+
<p>Rails 3.1 Release Notes were compiled by <a href="https://github.com/vijaydev">Vijay Dev</a>.</p>
|
622
|
+
|
623
|
+
<h3>Feedback</h3>
|
624
|
+
<p>
|
625
|
+
You're encouraged to help improve the quality of this guide.
|
626
|
+
</p>
|
627
|
+
<p>
|
628
|
+
If you see any typos or factual errors you are confident to
|
629
|
+
patch, please clone <a href="https://github.com/lifo/docrails">docrails</a>
|
630
|
+
and push the change yourself. That branch of Rails has public write access.
|
631
|
+
Commits are still reviewed, but that happens after you've submitted your
|
632
|
+
contribution. <a href="https://github.com/lifo/docrails">docrails</a> is
|
633
|
+
cross-merged with master periodically.
|
634
|
+
</p>
|
635
|
+
<p>
|
636
|
+
You may also find incomplete content, or stuff that is not up to date.
|
637
|
+
Please do add any missing documentation for master. Check the
|
638
|
+
<a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
|
639
|
+
for style and conventions.
|
640
|
+
</p>
|
641
|
+
<p>
|
642
|
+
If for whatever reason you spot something to fix but cannot patch it yourself, please
|
643
|
+
<a href="https://github.com/rails/rails/issues">open an issue</a>.
|
644
|
+
</p>
|
645
|
+
<p>And last but not least, any kind of discussion regarding Ruby on Rails
|
646
|
+
documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
|
647
|
+
</p>
|
648
|
+
</div>
|
649
|
+
</div>
|
650
|
+
</div>
|
651
|
+
|
652
|
+
<hr class="hide" />
|
653
|
+
<div id="footer">
|
654
|
+
<div class="wrapper">
|
655
|
+
<p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
|
656
|
+
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
657
|
+
</div>
|
658
|
+
</div>
|
659
|
+
|
660
|
+
<script type="text/javascript" src="javascripts/guides.js"></script>
|
661
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
662
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
663
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
664
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
665
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
666
|
+
<script type="text/javascript">
|
667
|
+
SyntaxHighlighter.all()
|
668
|
+
</script>
|
669
|
+
</body>
|
670
|
+
</html>
|