railties 3.1.0.rc5 → 3.1.0.rc6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/guides/rails_guides/generator.rb +4 -44
  2. data/guides/rails_guides/textile_extensions.rb +22 -3
  3. data/guides/source/3_1_release_notes.textile +429 -0
  4. data/guides/source/action_mailer_basics.textile +4 -2
  5. data/guides/source/active_record_validations_callbacks.textile +56 -13
  6. data/guides/source/active_resource_basics.textile +74 -0
  7. data/guides/source/active_support_core_extensions.textile +36 -0
  8. data/guides/source/asset_pipeline.textile +59 -60
  9. data/guides/source/command_line.textile +3 -1
  10. data/guides/source/configuring.textile +1 -1
  11. data/guides/source/getting_started.textile +11 -15
  12. data/guides/source/i18n.textile +1 -1
  13. data/guides/source/initialization.textile +4 -3
  14. data/guides/source/layouts_and_rendering.textile +2 -2
  15. data/guides/source/migrations.textile +23 -23
  16. data/guides/source/rails_application_templates.textile +1 -7
  17. data/lib/rails/application.rb +1 -3
  18. data/lib/rails/application/configuration.rb +1 -0
  19. data/lib/rails/engine.rb +3 -3
  20. data/lib/rails/generators/app_base.rb +12 -0
  21. data/lib/rails/generators/rails/app/templates/Gemfile +1 -8
  22. data/lib/rails/generators/rails/app/templates/config/application.rb +6 -4
  23. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +2 -2
  24. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +7 -3
  25. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +2 -2
  26. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +22 -7
  27. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +13 -7
  28. data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
  29. data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/{application.html.erb.tt → %name%/application.html.erb.tt} +0 -0
  30. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb +3 -0
  31. data/lib/rails/paths.rb +4 -0
  32. data/lib/rails/railtie.rb +1 -0
  33. data/lib/rails/tasks/misc.rake +1 -1
  34. data/lib/rails/version.rb +1 -1
  35. metadata +34 -12
@@ -199,50 +199,10 @@ module RailsGuides
199
199
  end
200
200
 
201
201
  def textile(body, lite_mode=false)
202
- # If the issue with notextile is fixed just remove the wrapper.
203
- with_workaround_for_notextile(body) do |body|
204
- t = RedCloth.new(body)
205
- t.hard_breaks = false
206
- t.lite_mode = lite_mode
207
- t.to_html(:notestuff, :plusplus, :code)
208
- end
209
- end
210
-
211
- # For some reason the notextile tag does not always turn off textile. See
212
- # LH ticket of the security guide (#7). As a temporary workaround we deal
213
- # with code blocks by hand.
214
- def with_workaround_for_notextile(body)
215
- code_blocks = []
216
-
217
- body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m|
218
- brush = case $1
219
- when 'ruby', 'sql', 'plain'
220
- $1
221
- when 'erb'
222
- 'ruby; html-script: true'
223
- when 'html'
224
- 'xml' # html is understood, but there are .xml rules in the CSS
225
- else
226
- 'plain'
227
- end
228
-
229
- code_blocks.push(<<HTML)
230
- <notextile>
231
- <div class="code_container">
232
- <pre class="brush: #{brush}; gutter: false; toolbar: false">
233
- #{ERB::Util.h($2).strip}
234
- </pre>
235
- </div>
236
- </notextile>
237
- HTML
238
- "\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n"
239
- end
240
-
241
- body = yield body
242
-
243
- body.gsub(%r{<p>dirty_workaround_for_notextile_(\d+)</p>}) do |_|
244
- code_blocks[$1.to_i]
245
- end
202
+ t = RedCloth.new(body)
203
+ t.hard_breaks = false
204
+ t.lite_mode = lite_mode
205
+ t.to_html(:notestuff, :plusplus, :code)
246
206
  end
247
207
 
248
208
  def warn_about_broken_links(html)
@@ -33,11 +33,30 @@ module RailsGuides
33
33
  body.gsub!('<plus>', '+')
34
34
  end
35
35
 
36
+ def brush_for(code_type)
37
+ case code_type
38
+ when 'ruby', 'sql', 'plain'
39
+ code_type
40
+ when 'erb'
41
+ 'ruby; html-script: true'
42
+ when 'html'
43
+ 'xml' # html is understood, but there are .xml rules in the CSS
44
+ else
45
+ 'plain'
46
+ end
47
+ end
48
+
36
49
  def code(body)
37
50
  body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m|
38
- es = ERB::Util.h($2)
39
- css_class = $1.in?(['erb', 'shell']) ? 'html' : $1
40
- %{<notextile><div class="code_container"><code class="#{css_class}">#{es}</code></div></notextile>}
51
+ <<HTML
52
+ <notextile>
53
+ <div class="code_container">
54
+ <pre class="brush: #{brush_for($1)}; gutter: false; toolbar: false">
55
+ #{ERB::Util.h($2).strip}
56
+ </pre>
57
+ </div>
58
+ </notextile>
59
+ HTML
41
60
  end
42
61
  end
43
62
  end
@@ -0,0 +1,429 @@
1
+ h2. Ruby on Rails 3.1 Release Notes
2
+
3
+ Highlights in Rails 3.1:
4
+
5
+ * Streaming
6
+ * Reversible Migrations
7
+ * Assets Pipeline
8
+ * jQuery as the default JavaScript library
9
+
10
+ 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 "list of commits":https://github.com/rails/rails/commits/master in the main Rails repository on GitHub.
11
+
12
+ endprologue.
13
+
14
+ h3. Upgrading to Rails 3.1
15
+
16
+ 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:
17
+
18
+ h4. Rails 3.1 requires at least Ruby 1.8.7
19
+
20
+ 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.
21
+
22
+ TIP: 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.
23
+
24
+ h3. Creating a Rails 3.1 application
25
+
26
+ <shell>
27
+ # You should have the 'rails' rubygem installed
28
+ $ rails new myapp
29
+ $ cd myapp
30
+ </shell>
31
+
32
+ h4. Vendoring Gems
33
+
34
+ Rails now uses a +Gemfile+ in the application root to determine the gems you require for your application to start. This +Gemfile+ is processed by the "Bundler":https://github.com/carlhuda/bundler 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.
35
+
36
+ More information: - "bundler homepage":http://gembundler.com
37
+
38
+ h4. Living on the Edge
39
+
40
+ +Bundler+ and +Gemfile+ makes freezing your Rails application easy as pie with the new dedicated +bundle+ command. If you want to bundle straight from the Git repository, you can pass the +--edge+ flag:
41
+
42
+ <shell>
43
+ $ rails new myapp --edge
44
+ </shell>
45
+
46
+ If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the +--dev+ flag:
47
+
48
+ <shell>
49
+ $ ruby /path/to/rails/bin/rails new myapp --dev
50
+ </shell>
51
+
52
+ h3. Rails Architectural Changes
53
+
54
+ h4. Assets Pipeline
55
+
56
+ The major change in Rails 3.1 is the Assets Pipeline. It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines.
57
+
58
+ The assets pipeline is powered by "Sprockets":https://github.com/sstephenson/sprockets and is covered in the "Asset Pipeline":asset_pipeline.html guide.
59
+
60
+ h4. HTTP Streaming
61
+
62
+ HTTP 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.
63
+
64
+ h4. Default JS library is now jQuery
65
+
66
+ jQuery is the default JavaScript library that ships with Rails 3.1. But if you use Prototype, it's simple to switch.
67
+
68
+ <shell>
69
+ $ rails new myapp -j prototype
70
+ </shell>
71
+
72
+ h4. Identity Map
73
+
74
+ 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.
75
+
76
+ Rails 3.1 comes with the identity map turned off by default.
77
+
78
+ h3. Railties
79
+
80
+ * jQuery is the new default JavaScript library.
81
+
82
+ * jQuery and Prototype are no longer vendored and is provided from now on by the jquery-rails and prototype-rails gems.
83
+
84
+ * The application generator accepts an option +-j+ which can be an arbitrary string. If passed "foo", the gem "foo-rails" is added to the +Gemfile+, 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.
85
+
86
+ * Generating an application or a plugin runs +bundle install+ unless +--skip-gemfile+ or +--skip-bundle+ is specified.
87
+
88
+ * The controller and resource generators will now automatically produce asset stubs (this can be turned off with +--skip-assets+). These stubs will use CoffeeScript and Sass, if those libraries are available.
89
+
90
+ * Scaffold and app generators use the Ruby 1.9 style hash when running on Ruby 1.9. To generate old style hash, +--old-style-hash+ can be passed.
91
+
92
+ * Scaffold controller generator creates format block for JSON instead of XML.
93
+
94
+ * Active Record logging is directed to STDOUT and shown inline in the console.
95
+
96
+ * Added +config.force_ssl+ configuration which loads <tt>Rack::SSL</tt> middleware and force all requests to be under HTTPS protocol.
97
+
98
+ * Added +rails plugin new+ command which generates a Rails plugin with gemspec, tests and a dummy application for testing.
99
+
100
+ * Added <tt>Rack::Etag</tt> and <tt>Rack::ConditionalGet</tt> to the default middleware stack.
101
+
102
+ * Added <tt>Rack::Cache</tt> to the default middleware stack.
103
+
104
+ * Engines received a major update - You can mount them at any path, enable assets, run generators etc.
105
+
106
+ h3. Action Pack
107
+
108
+ h4. Action Controller
109
+
110
+ * A warning is given out if the CSRF token authenticity cannot be verified.
111
+
112
+ * Specify +force_ssl+ in a controller to force the browser to transfer data via HTTPS protocol on that particular controller. To limit to specific actions, +:only+ or +:except+ can be used.
113
+
114
+ * Sensitive query string parameters specified in <tt>config.filter_parameters</tt> will now be filtered out from the request paths in the log.
115
+
116
+ * URL parameters which return +nil+ for +to_param+ are now removed from the query string.
117
+
118
+ * Added <tt>ActionController::ParamsWrapper</tt> to wrap parameters into a nested hash, and will be turned on for JSON request in new applications by default. This can be customized by setting <tt>ActionController::Base.wrap_parameters</tt> in <tt>config/initializer/wrap_parameters.rb</tt>.
119
+
120
+ * 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 +include_all_helpers+ to +false+ will result in including only application_helper and the helper corresponding to controller (like foo_helper for foo_controller).
121
+
122
+ * +url_for+ and named url helpers now accept +:subdomain+ and +:domain+ as options.
123
+
124
+ * Added +Base.http_basic_authenticate_with+ to do simple http basic authentication with a single class method call.
125
+
126
+ <ruby>
127
+ class PostsController < ApplicationController
128
+ USER_NAME, PASSWORD = "dhh", "secret"
129
+
130
+ before_filter :authenticate, :except => [ :index ]
131
+
132
+ def index
133
+ render :text => "Everyone can see me!"
134
+ end
135
+
136
+ def edit
137
+ render :text => "I'm only accessible if you know the password"
138
+ end
139
+
140
+ private
141
+ def authenticate
142
+ authenticate_or_request_with_http_basic do |user_name, password|
143
+ user_name == USER_NAME && password == PASSWORD
144
+ end
145
+ end
146
+ end
147
+ </ruby>
148
+
149
+ ..can now be written as
150
+
151
+ <ruby>
152
+ class PostsController < ApplicationController
153
+ http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
154
+
155
+ def index
156
+ render :text => "Everyone can see me!"
157
+ end
158
+
159
+ def edit
160
+ render :text => "I'm only accessible if you know the password"
161
+ end
162
+ end
163
+ </ruby>
164
+
165
+ * Added streaming support, you can enable it with:
166
+
167
+ <ruby>
168
+ class PostsController < ActionController::Base
169
+ stream
170
+ end
171
+ </ruby>
172
+
173
+ You can restrict it to some actions by using +:only+ or +:except+. Please read the docs at "<tt>ActionController::Streaming</tt>":http://edgeapi.rubyonrails.org/classes/ActionController/Streaming.html for more information.
174
+
175
+ * 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.
176
+
177
+ h4. Action Dispatch
178
+
179
+ * <tt>config.action_dispatch.x_sendfile_header</tt> now defaults to +nil+ 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>.
180
+
181
+ * <tt>ActionDispatch::MiddlewareStack</tt> now uses composition over inheritance and is no longer an array.
182
+
183
+ * Added <tt>ActionDispatch::Request.ignore_accept_header</tt> to ignore accept headers.
184
+
185
+ * Added <tt>Rack::Cache</tt> to the default stack.
186
+
187
+ * Moved etag responsibility from <tt>ActionDispatch::Response</tt> to the middleware stack.
188
+
189
+ * Rely on <tt>Rack::Session</tt> stores API 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>.
190
+
191
+ * Template lookup now searches further up in the inheritance chain.
192
+
193
+ h4. Action View
194
+
195
+ * Added an +:authenticity_token+ option to +form_tag+ for custom handling or to omit the token by passing <tt>:authenticity_token => false</tt>.
196
+
197
+ * Created <tt>ActionView::Renderer</tt> and specified an API for <tt>ActionView::Context</tt>.
198
+
199
+ * In place +SafeBuffer+ mutation is prohibited in Rails 3.1.
200
+
201
+ * Added HTML5 +button_tag+ helper.
202
+
203
+ * +file_field+ automatically adds <tt>:multipart => true</tt> to the enclosing form.
204
+
205
+ * Added a convenience idiom to generate HTML5 data-* attributes in tag helpers from a +:data+ hash of options:
206
+
207
+ <plain>
208
+ tag("div", :data => {:name => 'Stephen', :city_state => %w(Chicago IL)})
209
+ # => <div data-name="Stephen" data-city-state="[&quot;Chicago&quot;,&quot;IL&quot;]" />
210
+ </plain>
211
+
212
+ Keys are dasherized. Values are JSON-encoded, except for strings and symbols.
213
+
214
+ * +csrf_meta_tag+ is renamed to +csrf_meta_tags+ and aliases +csrf_meta_tag+ for backwards compatibility.
215
+
216
+ * The old template handler API is deprecated and the new API simply requires a template handler to respond to call.
217
+
218
+ * rhtml and rxml are finally removed as template handlers.
219
+
220
+ * <tt>config.action_view.cache_template_loading</tt> is brought back which allows to decide whether templates should be cached or not.
221
+
222
+ * The submit form helper does not generate an id "object_name_id" anymore.
223
+
224
+ * Allows <tt>FormHelper#form_for</tt> to specify the +:method+ as a direct option instead of through the +:html+ hash. <tt>form_for(==@==post, remote: true, method: :delete)</tt> instead of <tt>form_for(==@==post, remote: true, html: { method: :delete })</tt>.
225
+
226
+ * Provided <tt>JavaScriptHelper#j()</tt> as an alias for <tt>JavaScriptHelper#escape_javascript()</tt>. This supersedes the <tt>Object#j()</tt> method that the JSON gem adds within templates using the JavaScriptHelper.
227
+
228
+ * Allows AM/PM format in datetime selectors.
229
+
230
+ * +auto_link+ has been removed from Rails and extracted into the "rails_autolink gem":https://github.com/tenderlove/rails_autolink
231
+
232
+ h3. Active Record
233
+
234
+ * 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>.
235
+ <ruby>
236
+ class User < ActiveRecord::Base
237
+ self.pluralize_table_names = false
238
+ end
239
+ </ruby>
240
+
241
+ * Added block setting of attributes to singular associations. The block will get called after the instance is initialized.
242
+
243
+ <ruby>
244
+ class User < ActiveRecord::Base
245
+ has_one :account
246
+ end
247
+
248
+ user.build_account{ |a| a.credit_limit => 100.0 }
249
+ </ruby>
250
+
251
+ * 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.
252
+
253
+ * CSV Fixtures are deprecated and support will be removed in Rails 3.2.0.
254
+
255
+ * <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:
256
+
257
+ <ruby>
258
+ class Post < ActiveRecord::Base
259
+ attr_accessible :title
260
+ attr_accessible :title, :published_at, :as => :admin
261
+ end
262
+
263
+ Post.new(params[:post], :as => :admin)
264
+ </ruby>
265
+
266
+ * +default_scope+ can now take a block, lambda, or any other object which responds to call for lazy evaluation.
267
+
268
+ * 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.
269
+
270
+ * PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
271
+
272
+ * +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed.
273
+
274
+ * Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
275
+
276
+ * Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations.
277
+
278
+ * The configuration for the current database connection is now accessible via <tt>ActiveRecord::Base.connection_config</tt>.
279
+
280
+ * limits and offsets are removed from COUNT queries unless both are supplied.
281
+ <ruby>
282
+ People.limit(1).count # => 'SELECT COUNT(*) FROM people'
283
+ People.offset(1).count # => 'SELECT COUNT(*) FROM people'
284
+ People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
285
+ </ruby>
286
+
287
+ * <tt>ActiveRecord::Associations::AssociationProxy</tt> has been split. There is now an +Association+ class (and subclasses) which are responsible for operating on associations, and then a separate, thin wrapper called +CollectionProxy+, which proxies collection associations. This prevents namespace pollution, separates concerns, and will allow further refactorings.
288
+
289
+ * Singular associations (+has_one+, +belongs_to+) no longer have a proxy and simply returns the associated record or +nil+. This means that you should not use undocumented methods such as +bob.mother.create+ - use +bob.create_mother+ instead.
290
+
291
+ * Support the <tt>:dependent</tt> option on <tt>has_many :through</tt> associations. For historical and practical reasons, +:delete_all+ is the default deletion strategy employed by <tt>association.delete(*records)</tt>, despite the fact that the default strategy is +:nullify+ 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.
292
+
293
+ * The behavior of +association.destroy+ for +has_and_belongs_to_many+ 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'.
294
+
295
+ * 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.
296
+
297
+ * 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.
298
+
299
+ * 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>.
300
+
301
+ * Add <tt>:bulk => true</tt> option to +change_table+ to make all the schema changes defined in a block using a single ALTER statement.
302
+
303
+ <ruby>
304
+ change_table(:users, :bulk => true) do |t|
305
+ t.string :company_name
306
+ t.change :birthdate, :datetime
307
+ end
308
+ </ruby>
309
+
310
+ * Removed support for accessing attributes on a +has_and_belongs_to_many+ join table. <tt>has_many :through</tt> needs to be used.
311
+
312
+ * Added a +create_association!+ method for +has_one+ and +belongs_to+ associations.
313
+
314
+ * Migrations are now reversible, meaning that Rails will figure out how to reverse your migrations. To use reversible migrations, just define the +change+ method.
315
+ <ruby>
316
+ class MyMigration < ActiveRecord::Migration
317
+ def change
318
+ create_table(:horses) do
319
+ t.column :content, :text
320
+ t.column :remind_at, :datetime
321
+ end
322
+ end
323
+ end
324
+ </ruby>
325
+
326
+ * Some things cannot be automatically reversed for you. If you know how to reverse those things, you should define +up+ and +down+ in your migration. If you define something in change that cannot be reversed, an +IrreversibleMigration+ exception will be raised when going down.
327
+
328
+ * Migrations now use instance methods rather than class methods:
329
+ <ruby>
330
+ class FooMigration < ActiveRecord::Migration
331
+ def up # Not self.up
332
+ ...
333
+ end
334
+ end
335
+ </ruby>
336
+
337
+ * Migration files generated from model and constructive migration generators (for example, add_name_to_users) use the reversible migration's +change+ method instead of the ordinary +up+ and +down+ methods.
338
+
339
+ * Removed support for interpolating string SQL conditions on associations. Instead, a proc should be used.
340
+
341
+ <ruby>
342
+ has_many :things, :conditions => 'foo = #{bar}' # before
343
+ has_many :things, :conditions => proc { "foo = #{bar}" } # after
344
+ </ruby>
345
+
346
+ Inside the proc, +self+ is the object which is the owner of the association, unless you are eager loading the association, in which case +self+ is the class which the association is within.
347
+
348
+ You can have any "normal" conditions inside the proc, so the following will work too:
349
+ <ruby>
350
+ has_many :things, :conditions => proc { ["foo = ?", bar] }
351
+ </ruby>
352
+
353
+ * Previously +:insert_sql+ and +:delete_sql+ on +has_and_belongs_to_many+ association allowed you to call 'record' to get the record being inserted or deleted. This is now passed as an argument to the proc.
354
+
355
+ * Added <tt>ActiveRecord::Base#has_secure_password</tt> (via <tt>ActiveModel::SecurePassword</tt>) to encapsulate dead-simple password usage with BCrypt encryption and salting.
356
+ <ruby>
357
+ # Schema: User(name:string, password_digest:string, password_salt:string)
358
+ class User < ActiveRecord::Base
359
+ has_secure_password
360
+ end
361
+ </ruby>
362
+
363
+ * When a model is generated +add_index+ is added by default for +belongs_to+ or +references+ columns.
364
+
365
+ * Setting the id of a +belongs_to+ object will update the reference to the object.
366
+
367
+ * <tt>ActiveRecord::Base#dup</tt> and <tt>ActiveRecord::Base#clone</tt> semantics have changed to closer match normal Ruby dup and clone semantics.
368
+
369
+ * 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.
370
+
371
+ * 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 +true+ for <tt>new_record?</tt>, have a +nil+ id field, and is saveable.
372
+
373
+ * The query cache now works with prepared statements. No changes in the applications are required.
374
+
375
+ h3. Active Model
376
+
377
+ * +attr_accessible+ accepts an option +:as+ to specify a role.
378
+
379
+ * +InclusionValidator+, +ExclusionValidator+, and +FormatValidator+ now accepts an option which can be a proc, a lambda, or anything that respond to +call+. This option will be called with the current record as an argument and returns an object which respond to +include?+ for +InclusionValidator+ and +ExclusionValidator+, and returns a regular expression object for +FormatValidator+.
380
+
381
+ * Added <tt>ActiveModel::SecurePassword</tt> to encapsulate dead-simple password usage with BCrypt encryption and salting.
382
+
383
+ * <tt>ActiveModel::AttributeMethods</tt> allows attributes to be defined on demand.
384
+
385
+ * Added support for selectively enabling and disabling observers.
386
+
387
+ * Alternate <tt>I18n</tt> namespace lookup is no longer supported.
388
+
389
+ h3. Active Resource
390
+
391
+ * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set <tt>self.format = :xml</tt> in the class. For example,
392
+
393
+ <ruby>
394
+ class User < ActiveResource::Base
395
+ self.format = :xml
396
+ end
397
+ </ruby>
398
+
399
+ h3. Active Support
400
+
401
+ * <tt>ActiveSupport::Dependencies</tt> now raises +NameError+ if it finds an existing constant in +load_missing_constant+.
402
+
403
+ * Added a new reporting method <tt>Kernel#quietly</tt> which silences both +STDOUT+ and +STDERR+.
404
+
405
+ * Added <tt>String#inquiry</tt> as a convenience method for turning a String into a +StringInquirer+ object.
406
+
407
+ * Added <tt>Object#in?</tt> to test if an object is included in another object.
408
+
409
+ * +LocalCache+ strategy is now a real middleware class and no longer an anonymous class.
410
+
411
+ * <tt>ActiveSupport::Dependencies::ClassCache</tt> class has been introduced for holding references to reloadable classes.
412
+
413
+ * <tt>ActiveSupport::Dependencies::Reference</tt> has been refactored to take direct advantage of the new +ClassCache+.
414
+
415
+ * Backports <tt>Range#cover?</tt> as an alias for <tt>Range#include?</tt> in Ruby 1.8.
416
+
417
+ * Added +weeks_ago+ and +prev_week+ to Date/DateTime/Time.
418
+
419
+ * Added +before_remove_const+ callback to <tt>ActiveSupport::Dependencies.remove_unloadable_constants!</tt>.
420
+
421
+ Deprecations:
422
+
423
+ * <tt>ActiveSupport::SecureRandom</tt> is deprecated in favor of +SecureRandom+ from the Ruby standard library.
424
+
425
+ h3. Credits
426
+
427
+ See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.
428
+
429
+ Rails 3.1 Release Notes were compiled by "Vijay Dev":https://github.com/vijaydev.