Skip to content
This repository
Browse code

Updated 4.0 release notes

The release notes is changed to include only the major changes and point
to the changelogs for the complete list. This lets us talk more about the
features included in the upcoming release and make the guide more useful
and interesting than just a list of all changelogs.

This is still a WIP guide pending a lot of work.

[ci skip]
  • Loading branch information...
commit 9d3ce6c7d24fb8fe63f4bde4718e6af6225e5a98 1 parent 042f5eb
Vijay Dev vijaydev authored
BIN  guides/assets/images/rails4_features.png
867 guides/source/4_0_release_notes.md
Source Rendered
... ... @@ -1,42 +1,24 @@
1 1 Ruby on Rails 4.0 Release Notes
2 2 ===============================
3 3
4   -Highlights in Rails 4.0: (WIP)
  4 +Highlights in Rails 4.0:
5 5
6 6 * Ruby 1.9.3 only
7 7 * Strong Parameters
8 8 * Queue API
9   -* Caching Improvements
10   -* ActionController::Live
  9 +* Turbolinks
  10 +* Russian Doll Caching
  11 +* Asynchronous Mailers
11 12
12   -These release notes cover the major changes, but do not include each bug-fix and changes. 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.
  13 +These release notes cover only the major changes. To know about various bug fixes and changes, please refer to the change logs or check out the [list of commits](https://github.com/rails/rails/commits/master) in the main Rails repository on GitHub.
13 14
14 15 --------------------------------------------------------------------------------
15 16
16 17 Upgrading to Rails 4.0
17 18 ----------------------
18 19
19   -TODO. This is a WIP guide.
  20 +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.2 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 4.0. A list of things to watch out for when upgrading is available in the [Upgrading to Rails](upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0) guide.
20 21
21   -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.2 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 4.0. Then take heed of the following changes:
22   -
23   -### Rails 4.0 requires at least Ruby 1.9.3
24   -
25   -Rails 4.0 requires Ruby 1.9.3 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible.
26   -
27   -### What to update in your apps
28   -
29   -* Update your Gemfile to depend on
30   - * `rails = 4.0.0`
31   - * `sass-rails ~> 3.2.3`
32   - * `coffee-rails ~> 3.2.1`
33   - * `uglifier >= 1.0.3`
34   -
35   -TODO: Update the versions above.
36   -
37   -* Rails 4.0 removes `vendor/plugins` completely. You have to replace these plugins by extracting them as gems and adding them in your Gemfile. If you choose not to make them gems, you can move them into, say, `lib/my_plugin/*` and add an appropriate initializer in `config/initializers/my_plugin.rb`.
38   -
39   -TODO: Configuration changes in environment files
40 22
41 23 Creating a Rails 4.0 application
42 24 --------------------------------
@@ -70,11 +52,14 @@ $ ruby /path/to/rails/railties/bin/rails new myapp --dev
70 52 Major Features
71 53 --------------
72 54
73   -Moved to a Plugin
74   ------------------
  55 +TODO. Give a list and then talk about each of them briefly. We can point to relevant code commits or documentation from these sections.
  56 +
  57 +![Rails 4.0](images/rails4_features.png)
75 58
76   -With Rails 4 several pieces have been extracted. While Rails won't ship with these features anymore,
77   -you can simply add the extracted plugin to your `Gemfile` to bring the functionality back.
  59 +Extraction of features to gems
  60 +---------------------------
  61 +
  62 +In Rails 4.0, several features have been extracted into gems. You can simply add the extracted gems to your `Gemfile` to bring the functionality back.
78 63
79 64 * Hash-based & Dynamic finder methods ([Github](https://github.com/rails/activerecord-deprecated_finders))
80 65 * Mass assignment protection in Active Record models ([Github](https://github.com/rails/protected_attributes), [Pull Request](https://github.com/rails/rails/pull/7251))
@@ -83,6 +68,7 @@ you can simply add the extracted plugin to your `Gemfile` to bring the functiona
83 68 * Active Resource ([Github](https://github.com/rails/activeresource), [Pull Request](https://github.com/rails/rails/pull/572), [Blog](http://yetimedia.tumblr.com/post/35233051627/activeresource-is-dead-long-live-activeresource))
84 69 * Action Caching ([Github](https://github.com/rails/actionpack-action_caching), [Pull Request](https://github.com/rails/rails/pull/7833))
85 70 * Page Caching ([Github](https://github.com/rails/actionpack-page_caching), [Pull Request](https://github.com/rails/rails/pull/7833))
  71 +* Sprockets ([Github](https://github.com/rails/sprockets-rails))
86 72
87 73 Documentation
88 74 -------------
@@ -94,848 +80,93 @@ Documentation
94 80 Railties
95 81 --------
96 82
97   -* Ensure that RAILS_ENV is set when accessing Rails.env.
98   -
99   -* Don't eager-load app/assets and app/views.
  83 +Please refer to the [Changelog](https://github.com/rails/rails/blob/master/railties/CHANGELOG.md) for detailed changes.
100 84
101   -* Add `.rake` to list of file extensions included by `rake notes` and `rake notes:custom`.
  85 +### Notable changes
102 86
103 87 * New test locations `test/models`, `test/helpers`, `test/controllers`, and `test/mailers`. Corresponding rake tasks added as well. ([Pull Request](https://github.com/rails/rails/pull/7878))
104 88
105   -* Set a different cache per environment for assets pipeline through `config.assets.cache`.
106   -
107   -* `Rails.public_path` now returns a Pathname object.
108   -
109   -* Remove highly uncommon `config.assets.manifest` option for moving the manifest path. This option is now unsupported in sprockets-rails.
110   -
111   -* Add `config.action_controller.permit_all_parameters` to disable StrongParameters protection, it's false by default.
112   -
113   -* Remove `config.active_record.whitelist_attributes` and `config.active_record.mass_assignment_sanitizer` from new applications since MassAssignmentSecurity has been extracted from Rails.
114   -
115   -* Change `rails new` and `rails plugin new` generators to name the `.gitkeep` files as `.keep` in a more SCM-agnostic way. Change `--skip-git` option to only skip the `.gitignore` file and still generate the `.keep` files. Add `--skip-keeps` option to skip the `.keep` files.
116   -
117   -* Fixed support for DATABASE_URL environment variable for rake db tasks.
118   -
119   -* rails dbconsole now can use SSL for MySQL. The database.yml options sslca, sslcert, sslcapath, sslcipher and sslkey now affect rails dbconsole.
120   -
121   -* Correctly handle SCRIPT_NAME when generating routes to engine in application that's mounted at a sub-uri. With this behavior, you *should not* use default_url_options[:script_name] to set proper application's mount point by yourself.
122   -
123   -* `config.threadsafe!` is deprecated in favor of `config.eager_load` which provides a more fine grained control on what is eager loaded.
124   -
125   -* The migration generator will now produce AddXXXToYYY/RemoveXXXFromYYY migrations with references statements, for instance
126   -
127   - rails g migration AddReferencesToProducts user:references supplier:references{polymorphic}
128   -
129   - will generate the migration with:
130   -
131   - add_reference :products, :user, index: true
132   - add_reference :products, :supplier, polymorphic: true, index: true
133   -
134   -* Allow scaffold/model/migration generators to accept a `polymorphic` modifier for `references`/`belongs_to`, for instance
135   -
136   - ```
137   - rails g model Product supplier:references{polymorphic}
138   - ```
139   -
140   - will generate the model with `belongs_to :supplier, polymorphic: true` association and appropriate migration.
141   -
142   -* Set `config.active_record.migration_error` to `:page_load` for development.
143   -
144   -* Add runner to `Rails::Railtie` as a hook called just after runner starts.
145   -
146   -* Add `/rails/info/routes` path which displays the same information as `rake routes`.
147   -
148   -* Improved `rake routes` output for redirects.
149   -
150   -* Load all environments available in `config.paths["config/environments"]`.
151   -
152   -* Add `config.queue_consumer` to change the job queue consumer from the default `ActiveSupport::ThreadedQueueConsumer`.
153   -
154   -* Add `Rails.queue` for processing jobs in the background.
155   -
156   -* Remove `Rack::SSL` in favour of `ActionDispatch::SSL`.
157   -
158   -* Allow to set class that will be used to run as a console, other than IRB, with `Rails.application.config.console=`. It's best to add it to console block.
159   -
160   - ```ruby
161   - # it can be added to config/application.rb
162   - console do
163   - # this block is called only when running console,
164   - # so we can safely require pry here
165   - require "pry"
166   - config.console = Pry
167   - end
168   - ```
169   -
170   -* Add a convenience method `hide!` to Rails generators to hide the current generator namespace from showing when running `rails generate`.
  89 +* Threadsafe on by default
171 90
172   -* Scaffold now uses `content_tag_for` in `index.html.erb`.
173   -
174   -* `Rails::Plugin` is removed. Instead of adding plugins to `vendor/plugins`, use gems or bundler with path or git dependencies.
  91 +* Add `Rails.queue` for processing jobs in the background.
175 92
176 93 ### Deprecations
177 94
178   -Action Mailer
179   --------------
180   -
181   -* Allow to set default Action Mailer options via `config.action_mailer.default_options=`.
182   -
183   -* Raise an `ActionView::MissingTemplate` exception when no implicit template could be found.
184   -
185   -* Asynchronously send messages via the Rails Queue. ([Pull Request](https://github.com/rails/rails/pull/6839))
186   -
187   -* Delivery Options (such as SMTP Settings) can now be set dynamically per mailer action.
188   -
189   - Delivery options are set via <tt>:delivery_method_options</tt> key on mail.
190   -
191   - ```ruby
192   - def welcome_mailer(user,company)
193   - delivery_options = { user_name: company.smtp_user, password: company.smtp_password, address: company.smtp_host }
194   - mail(to: user.email, subject: "Welcome!", delivery_method_options: delivery_options)
195   - end
196   - ```
197   -
198   -* Allow for callbacks in mailers similar to ActionController::Base. You can now set up headers/attachments using `before_filter` or `after_filter`. You could also change delivery settings or prevent delivery in an after filter based on instance variables set in your mailer action. You have access to `ActionMailer::Base` instance methods like `message`, `attachments`, `headers`.
199   -
200   -Action Pack
201   ------------
202   -
203   -### Action Controller
204   -
205   -* Add `ActionController::Flash.add_flash_types` method to allow people to register their own flash types. e.g.:
206   -
207   - ```ruby
208   - class ApplicationController
209   - add_flash_types :error, :warning
210   - end
211   - ```
212   -
213   - If you add the above code, you can use `<%= error %>` in an erb, and `redirect_to /foo, :error => 'message'` in a controller.
214   -
215   -* Encrypted Cookies + Sign using Derived Keys. ([Pull Request](https://github.com/rails/rails/pull/8112))
216   -
217   -* Remove Active Model dependency from Action Pack.
218   -
219   -* Support unicode characters in routes. Route will be automatically escaped, so instead of manually escaping:
220   -
221   - ```ruby
222   - get Rack::Utils.escape('こんにちは') => 'home#index'
223   - ```
224   -
225   - You just have to write the unicode route:
226   -
227   - ```ruby
228   - get 'こんにちは' => 'home#index'
229   - ```
230   -
231   -* Return proper format on exceptions.
232   -
233   -* Extracted redirect logic from `ActionController::ForceSSL::ClassMethods.force_ssl` into `ActionController::ForceSSL#force_ssl_redirect`.
234   -
235   -* URL path parameters with invalid encoding now raise `ActionController::BadRequest`.
236   -
237   -* Malformed query and request parameter hashes now raise `ActionController::BadRequest`.
238   -
239   -* `respond_to` and `respond_with` now raise `ActionController::UnknownFormat` instead of directly returning head 406. The exception is rescued and converted to 406 in the exception handling middleware.
240   -
241   -* JSONP now uses `application/javascript` instead of `application/json` as the MIME type.
242   -
243   -* Session arguments passed to process calls in functional tests are now merged into the existing session, whereas previously they would replace the existing session. This change may break some existing tests if they are asserting the exact contents of the session but should not break existing tests that only assert individual keys.
244   -
245   -* Forms of persisted records use always PATCH (via the `_method` hack).
246   -
247   -* For resources, both PATCH and PUT are routed to the `update` action.
248   -
249   -* Don't ignore `force_ssl` in development. This is a change of behavior - use an `:if` condition to recreate the old behavior.
250   -
251   - ```ruby
252   - class AccountsController < ApplicationController
253   - force_ssl :if => :ssl_configured?
254   -
255   - def ssl_configured?
256   - !Rails.env.development?
257   - end
258   - end
259   - ```
260   -
261   -#### Deprecations
262   -
263   -* Deprecated `ActionController::Integration` in favour of `ActionDispatch::Integration`.
264   -
265   -* Deprecated `ActionController::IntegrationTest` in favour of `ActionDispatch::IntegrationTest`.
266   -
267   -* Deprecated `ActionController::PerformanceTest` in favour of `ActionDispatch::PerformanceTest`.
268   -
269   -* Deprecated `ActionController::AbstractRequest` in favour of `ActionDispatch::Request`.
270   -
271   -* Deprecated `ActionController::Request` in favour of `ActionDispatch::Request`.
272   -
273   -* Deprecated `ActionController::AbstractResponse` in favour of `ActionDispatch::Response`.
274   -
275   -* Deprecated `ActionController::Response` in favour of `ActionDispatch::Response`.
276   -
277   -* Deprecated `ActionController::Routing` in favour of `ActionDispatch::Routing`.
278   -
279   -### Action Dispatch
280   -
281   -* Add Routing Concerns to declare common routes that can be reused inside others resources and routes.
282   -
283   - Code before:
284   -
285   - ```ruby
286   - resources :messages do
287   - resources :comments
288   - end
289   -
290   - resources :posts do
291   - resources :comments
292   - resources :images, only: :index
293   - end
294   - ```
295   -
296   - Code after:
297   -
298   - ```ruby
299   - concern :commentable do
300   - resources :comments
301   - end
302   -
303   - concern :image_attachable do
304   - resources :images, only: :index
305   - end
306   -
307   - resources :messages, concerns: :commentable
308   -
309   - resources :posts, concerns: [:commentable, :image_attachable]
310   - ```
311   -
312   -* Show routes in exception page while debugging a `RoutingError` in development.
313   -
314   -* Helper methods for HTML5 inputs. ([Pull Request](https://github.com/rails/rails/pull/6359))
315   -
316   -* Include `mounted_helpers` (helpers for accessing mounted engines) in `ActionDispatch::IntegrationTest` by default.
317   -
318   -* Added `ActionDispatch::SSL` middleware that when included force all the requests to be under HTTPS protocol.
319   -
320   -* Copy literal route constraints to defaults so that url generation know about them. The copied constraints are `:protocol`, `:subdomain`, `:domain`, `:host` and `:port`.
321   -
322   -* Allows `assert_redirected_to` to match against a regular expression.
323   -
324   -* Adds a backtrace to the routing error page in development.
325   -
326   -* `assert_generates`, `assert_recognizes`, and `assert_routing` all raise `Assertion` instead of `RoutingError`.
327   -
328   -* Allows the route helper root to take a string argument. For example, `root 'pages#main'` as a shortcut for `root to: 'pages#main'`.
329   -
330   -* Adds support for the PATCH verb: Request objects respond to `patch?`. Routes now have a new `patch` method, and understand `:patch` in the existing places where a verb is configured, like `:via`. Functional tests have a new method `patch` and integration tests have a new method `patch_via_redirect`.
331   -If `:patch` is the default verb for updates, edits are tunneled as `PATCH` rather than as `PUT` and routing acts accordingly.
332   -
333   -* Integration tests support the OPTIONS method.
334   -
335   -* `expires_in` accepts a `must_revalidate` flag. If true, "must-revalidate" is added to the `Cache-Control` header.
336   -
337   -* Default responder will now always use your overridden block in `respond_with` to render your response.
338   -
339   -* Turn off verbose mode of `rack-cache`, we still have `X-Rack-Cache` to check that info.
340   -
341   -#### Deprecations
342   -
343   -### Action View
344   -
345   -* Remove Active Model dependency from Action Pack.
346   -
347   -* Allow to use `mounted_helpers` (helpers for accessing mounted engines) in `ActionView::TestCase`.
348   -
349   -* Make current object and counter (when it applies) variables accessible when rendering templates with `:object` or `:collection`.
350   -
351   -* Allow to lazy load `default_form_builder` by passing a string instead of a constant.
352   -
353   -* Add index method to `FormBuilder` class.
354   -
355   -* Adds support for layouts when rendering a partial with a given collection.
356   -
357   -* Remove `:disable_with` in favor of `data-disable-with` option from `submit_tag`, `button_tag` and `button_to` helpers.
358   -
359   -* Remove `:mouseover` option from `image_tag` helper.
360   -
361   -* Templates without a handler extension now raises a deprecation warning but still defaults to `ERb`. In future releases, it will simply return the template content.
362   -
363   -* Add a `divider` option to `grouped_options_for_select` to generate a separator optgroup automatically, and deprecate prompt as third argument, in favor of using an options hash.
364   -
365   -* Add `time_field` and `time_field_tag` helpers which render an `input[type="time"]` tag.
366   -
367   -* Removed old `text_helper` apis for `highlight`, `excerpt` and `word_wrap`.
368   -
369   -* Remove the leading \n added by textarea on `assert_select`.
370   -
371   -* Changed default value for `config.action_view.embed_authenticity_token_in_remote_forms` to false. This change breaks remote forms that need to work also without JavaScript, so if you need such behavior, you can either set it to true or explicitly pass `:authenticity_token => true` in form options.
372   -
373   -* Make possible to use a block in `button_to` helper if button text is hard to fit into the name parameter:
374   -
375   - ```ruby
376   - <%= button_to [:make_happy, @user] do %>
377   - Make happy <strong><%= @user.name %></strong>
378   - <% end %>
379   - # => "<form method="post" action="/users/1/make_happy" class="button_to">
380   - # <div>
381   - # <button type="submit">
382   - # Make happy <strong>Name</strong>
383   - # </button>
384   - # </div>
385   - # </form>"
386   - ```
387   -
388   -* Replace `include_seconds` boolean argument with `:include_seconds => true` option in `distance_of_time_in_words` and `time_ago_in_words` signature.
389   -
390   -* Remove `button_to_function` and `link_to_function` helpers.
391   -
392   -* `truncate` now always returns an escaped HTML-safe string. The option `:escape` can be used as `false` to not escape the result.
393   -
394   -* `truncate` now accepts a block to show extra content when the text is truncated.
395   -
396   -* Add `week_field`, `week_field_tag`, `month_field`, `month_field_tag`, `datetime_local_field`, `datetime_local_field_tag`, `datetime_field` and `datetime_field_tag` helpers.
397   -
398   -* Add `color_field` and `color_field_tag` helpers.
399   -
400   -* Add `include_hidden` option to select tag. With `:include_hidden => false` select with multiple attribute doesn't generate hidden input with blank value.
401   -
402   -* Removed default size option from the `text_field`, `search_field`, `telephone_field`, `url_field`, `email_field` helpers.
403   -
404   -* Removed default cols and rows options from the `text_area` helper.
405   -
406   -* Adds `image_url`, `javascript_url`, `stylesheet_url`, `audio_url`, `video_url`, and `font_url` to assets tag helper. These URL helpers will return the full path to your assets. This is useful when you are going to reference this asset from external host.
407   -
408   -* Allow `value_method` and `text_method` arguments from `collection_select` and `options_from_collection_for_select` to receive an object that responds to `:call` such as a proc, to evaluate the option in the current element context. This works the same way with `collection_radio_buttons` and `collection_check_boxes`.
409   -
410   -* Add `date_field` and `date_field_tag` helpers which render an `input[type="date"]` tag.
411   -
412   -* Add `collection_check_boxes` form helper, similar to `collection_select`:
413   -
414   - ```ruby
415   - collection_check_boxes :post, :author_ids, Author.all, :id, :name
416   - # Outputs something like:
417   - <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" />
418   - <label for="post_author_ids_1">D. Heinemeier Hansson</label>
419   - <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
420   - <label for="post_author_ids_2">D. Thomas</label>
421   - <input name="post[author_ids][]" type="hidden" value="" />
422   - ```
423   -
424   - The label/check_box pairs can be customized with a block.
425   -
426   -* Add `collection_radio_buttons` form helper, similar to `collection_select`:
427   -
428   - ```ruby
429   - collection_radio_buttons :post, :author_id, Author.all, :id, :name
430   - # Outputs something like:
431   - <input id="post_author_id_1" name="post[author_id]" type="radio" value="1" />
432   - <label for="post_author_id_1">D. Heinemeier Hansson</label>
433   - <input id="post_author_id_2" name="post[author_id]" type="radio" value="2" />
434   - <label for="post_author_id_2">D. Thomas</label>
435   - ```
436   -
437   - The label/radio_button pairs can be customized with a block.
438   -
439   -* `check_box` with an HTML5 attribute `:form` will now replicate the `:form` attribute to the hidden field as well.
440   -
441   -* label form helper accepts `:for => nil` to not generate the attribute.
442   -
443   -* Add `:format` option to `number_to_percentage`.
444   -
445   -* Add `config.action_view.logger` to configure logger for `Action View`.
  95 +* `config.threadsafe!` is deprecated in favor of `config.eager_load` which provides a more fine grained control on what is eager loaded.
446 96
447   -* `check_box` helper with `:disabled => true` will generate a `disabled` hidden field to conform with the HTML convention where disabled fields are not submitted with the form. This is a behavior change, previously the hidden tag had a value of the disabled checkbox.
  97 +* `Rails::Plugin` has gone. Instead of adding plugins to `vendor/plugins` use gems or bundler with path or git dependencies.
448 98
449   -* `favicon_link_tag` helper will now use the favicon in `app/assets` by default.
450   -
451   -* `ActionView::Helpers::TextHelper#highlight` now defaults to the HTML5 `mark` element.
452   -
453   -#### Deprecations
454   -
455   -### Sprockets
456   -
457   -Moved into a separate gem `sprockets-rails`.
458   -
459   -Active Record
  99 +Action Mailer
460 100 -------------
461 101
462   -* Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to` and `remove_belongs_to` are acceptable. References are reversible.
463   -
464   - ```ruby
465   - # Create a user_id column
466   - add_reference(:products, :user)
467   -
468   - # Create a supplier_id, supplier_type columns and appropriate index
469   - add_reference(:products, :supplier, polymorphic: true, index: true)
470   -
471   - # Remove polymorphic reference
472   - remove_reference(:products, :supplier, polymorphic: true)
473   - ```
474   -
475   -* Add `:default` and `:null` options to `column_exists?`.
476   -
477   - ```ruby
478   - column_exists?(:testings, :taggable_id, :integer, null: false)
479   - column_exists?(:testings, :taggable_type, :string, default: 'Photo')
480   - ```
481   -
482   -* `ActiveRecord::Relation#inspect` now makes it clear that you are dealing with a `Relation` object rather than an array:
483   -
484   - ```ruby
485   - User.where(:age => 30).inspect
486   - # => <ActiveRecord::Relation [#<User ...>, #<User ...>]>
487   -
488   - User.where(:age => 30).to_a.inspect
489   - # => [#<User ...>, #<User ...>]
490   - ```
491   -
492   - if more than 10 items are returned by the relation, inspect will only show the first 10 followed by ellipsis.
493   -
494   -* Add `:collation` and `:ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
495   -
496   - ```yaml
497   - development:
498   - adapter: postgresql
499   - host: localhost
500   - database: rails_development
501   - username: foo
502   - password: bar
503   - encoding: UTF8
504   - collation: ja_JP.UTF8
505   - ctype: ja_JP.UTF8
506   - ```
507   -
508   -* `FinderMethods#exists?` now returns `false` with the `false` argument.
509   -
510   -* Added support for specifying the precision of a timestamp in the postgresql adapter. So, instead of having to incorrectly specify the precision using the `:limit` option, you may use `:precision`, as intended. For example, in a migration:
511   -
512   - ```ruby
513   - def change
514   - create_table :foobars do |t|
515   - t.timestamps :precision => 0
516   - end
517   - end
518   - ```
519   -
520   -* Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an array of arrays containing the typecasted values:
521   -
522   - ```ruby
523   - Person.pluck(:id, :name)
524   - # SELECT people.id, people.name FROM people
525   - # => [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
526   - ```
527   -
528   -* Improve the derivation of HABTM join table name to take account of nesting. It now takes the table names of the two models, sorts them lexically and then joins them, stripping any common prefix from the second table name. Some examples:
529   -
530   - ```
531   - Top level models (Category <=> Product)
532   - Old: categories_products
533   - New: categories_products
534   -
535   - Top level models with a global table_name_prefix (Category <=> Product)
536   - Old: site_categories_products
537   - New: site_categories_products
538   -
539   - Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product)
540   - Old: categories_products
541   - New: categories_products
542   -
543   - Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product)
544   - Old: categories_products
545   - New: admin_categories_products
546   -
547   - Nested models in a parent model (Catalog::Category <=> Catalog::Product)
548   - Old: categories_products
549   - New: catalog_categories_products
550   -
551   - Nested models in different parent models (Catalog::Category <=> Content::Page)
552   - Old: categories_pages
553   - New: catalog_categories_content_pages
554   - ```
555   -
556   -* Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of this is to move when the exceptions are raised from the point of declaration to when the association is built. This is consistant with other association validity checks.
557   -
558   -* Added `stored_attributes` hash which contains the attributes stored using `ActiveRecord::Store`. This allows you to retrieve the list of attributes you've defined.
559   -
560   - ```ruby
561   - class User < ActiveRecord::Base
562   - store :settings, accessors: [:color, :homepage]
563   - end
564   -
565   - User.stored_attributes[:settings] # [:color, :homepage]
566   - ```
567   -
568   -* PostgreSQL default log level is now 'warning', to bypass the noisy notice messages. You can change the log level using the `min_messages` option available in your `config/database.yml`.
569   -
570   -* Add uuid datatype support to PostgreSQL adapter.
571   -
572   -* Added `ActiveRecord::Migration.check_pending!` that raises an error if migrations are pending.
573   -
574   -* Added `#destroy!` which acts like `#destroy` but will raise an `ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
575   -
576   -* Allow blocks for count with `ActiveRecord::Relation`, to work similar as `Array#count`: `Person.where("age > 26").count { |person| person.gender == 'female' }`
577   -
578   -* Added support to `CollectionAssociation#delete` for passing fixnum or string values as record ids. This finds the records responding to the ids and deletes them.
579   -
580   - ```ruby
581   - class Person < ActiveRecord::Base
582   - has_many :pets
583   - end
584   -
585   - person.pets.delete("1") # => [#<Pet id: 1>]
586   - person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
587   - ```
588   -
589   -* It's not possible anymore to destroy a model marked as read only.
590   -
591   -* Added ability to `ActiveRecord::Relation#from` to accept other `ActiveRecord::Relation` objects.
592   -
593   -* Added custom coders support for `ActiveRecord::Store`. Now you can set your custom coder like this:
594   -
595   - ```ruby
596   - store :settings, accessors: [ :color, :homepage ], coder: JSON
597   - ```
598   -
599   -* `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by default to avoid silent data loss. This can be disabled by specifying `strict: false` in `config/database.yml`. ([Pull Request](https://github.com/rails/rails/pull/6069))
600   -
601   -* Added default order to `ActiveRecord::Base#first` to assure consistent results among different database engines. Introduced `ActiveRecord::Base#take` as a replacement to the old behavior.
602   -
603   -* Added an `:index` option to automatically create indexes for `references` and `belongs_to` statements in migrations. This can be either a boolean or a hash that is identical to options available to the `add_index` method:
604   -
605   - ```ruby
606   - create_table :messages do |t|
607   - t.references :person, :index => true
608   - end
609   - ```
610   -
611   - Is the same as:
612   -
613   - ```ruby
614   - create_table :messages do |t|
615   - t.references :person
616   - end
617   - add_index :messages, :person_id
618   - ```
619   -
620   - Generators have also been updated to use the new syntax.
621   -
622   -* Added bang methods for mutating `ActiveRecord::Relation` objects. For example, while `foo.where(:bar)` will return a new object leaving foo unchanged, `foo.where!(:bar)` will mutate the foo object.
623   -
624   -* Added `#find_by` and `#find_by!` to mirror the functionality provided by dynamic finders in a way that allows dynamic input more easily:
625   -
626   - ```ruby
627   - Post.find_by name: 'Spartacus', rating: 4
628   - Post.find_by "published_at < ?", 2.weeks.ago
629   - Post.find_by! name: 'Spartacus'
630   - ```
631   -
632   -* Added `ActiveRecord::Base#slice` to return a hash of the given methods with their names as keys and returned values as values.
633   -
634   -* Remove IdentityMap - IdentityMap has never graduated to be an "enabled-by-default" feature, due to some inconsistencies with associations, as described in this [commit](https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6). Hence the removal from the codebase, until such issues are fixed.
635   -
636   -* Added a feature to dump/load internal state of `SchemaCache` instance because we want to boot more quickly when we have many models. ([Pull Request](https://github.com/rails/rails/pull/5162))
637   -
638   - ```ruby
639   - # execute rake task.
640   - RAILS_ENV=production bundle exec rake db:schema:cache:dump
641   - => generate db/schema_cache.dump
642   -
643   - # add config.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
644   -
645   - # boot rails.
646   - RAILS_ENV=production bundle exec rails server
647   - => use db/schema_cache.dump
648   -
649   - # If you remove clear dumped cache, execute rake task.
650   - RAILS_ENV=production bundle exec rake db:schema:cache:clear
651   - => remove db/schema_cache.dump
652   - ```
653   -
654   -* Added support for partial indices to `PostgreSQL` adapter.
655   -
656   -* The `add_index` method now supports a `where` option that receives a string with the partial index criteria.
657   -
658   -* Added the `ActiveRecord::NullRelation` class implementing the null object pattern for the Relation class.
659   -
660   -* Implemented `ActiveRecord::Relation#none` method which returns a chainable relation with zero records (an instance of the `NullRelation` class). Any subsequent condition chained to the returned relation will continue generating an empty relation and will not fire any query to the database.
661   -
662   -* Added `create_join_table` migration helper to create HABTM join tables.
663   -
664   - ```ruby
665   - create_join_table :products, :categories
666   - # =>
667   - # create_table :categories_products, :id => false do |td|
668   - # td.integer :product_id, :null => false
669   - # td.integer :category_id, :null => false
670   - # end
671   - ```
672   -
673   -* The primary key is always initialized in the `@attributes` hash to nil (unless another value has been specified).
674   -
675   -* In previous releases, the following would generate a single query with an OUTER JOIN comments, rather than two separate queries:
676   -
677   - ```ruby
678   - Post.includes(:comments).where("comments.name = 'foo'")
679   - ```
  102 +Please refer to the [Changelog](https://github.com/rails/rails/blob/master/actionmailer/CHANGELOG.md) for detailed changes.
680 103
681   - This behaviour relies on matching SQL string, which is an inherently flawed idea unless we write an SQL parser, which we do not wish to do. Therefore, it is now deprecated.
  104 +### Notable changes
682 105
683   - To avoid deprecation warnings and for future compatibility, you must explicitly state which tables you reference, when using SQL snippets:
684   -
685   - ```ruby
686   - Post.includes(:comments).where("comments.name = 'foo'").references(:comments)
687   - ```
688   -
689   - Note that you do not need to explicitly specify references in the following cases, as they can be automatically inferred:
690   -
691   - ```ruby
692   - Post.where(comments: { name: 'foo' })
693   - Post.where('comments.name' => 'foo')
694   - Post.order('comments.name')
695   - ```
696   -
697   - You also do not need to worry about this unless you are doing eager loading. Basically, don't worry unless you see a deprecation warning or (in future releases) an SQL error due to a missing JOIN.
698   -
699   -* Support for the `schema_info` table has been dropped. Please switch to `schema_migrations`.
700   -
701   -* Connections *must* be closed at the end of a thread. If not, your connection pool can fill and an exception will be raised.
702   -
703   -* PostgreSQL hstore records can be created.
704   -
705   -* PostgreSQL hstore types are automatically deserialized from the database.
706   -
707   -* Support for array datatype in PostgreSQL. ([Pull Request](https://github.com/rails/rails/pull/7547))
708   -
709   -* Added `#update_columns` method which updates the attributes from the passed-in hash without calling save, hence skipping validations and callbacks. `ActiveRecordError` will be raised when called on new objects or when at least one of the attributes is marked as read only.
710   -
711   - ```ruby
712   - post.attributes # => {"id"=>2, "title"=>"My title", "body"=>"My content", "author"=>"Peter"}
713   - post.update_columns({title: 'New title', author: 'Sebastian'}) # => true
714   - post.attributes # => {"id"=>2, "title"=>"New title", "body"=>"My content", "author"=>"Sebastian"}
715   - ```
  106 +* Asynchronously send messages via the Rails Queue. ([Pull Request](https://github.com/rails/rails/pull/6839))
716 107
717 108 ### Deprecations
718 109
719   -* Deprecated most of the 'dynamic finder' methods. All dynamic methods except for `find_by_...` and `find_by_...!` are deprecated. Here's how you can rewrite the code:
720   -
721   - ```ruby
722   - find_all_by_... can be rewritten using where(...)
723   - find_last_by_... can be rewritten using where(...).last
724   - scoped_by_... can be rewritten using where(...)
725   - find_or_initialize_by_... can be rewritten using where(...).first_or_initialize
726   - find_or_create_by_... can be rewritten using where(...).first_or_create
727   - find_or_create_by_...! can be rewritten using where(...).first_or_create!
728   - ```
729   -
730   - The implementation of the deprecated dynamic finders has been moved to the `active_record_deprecated_finders` gem.
731   -
732   -* Deprecated the old-style hash based finder API. This means that methods which previously accepted "finder options" no longer do. For example this:
733   -
734   - ```ruby
735   - Post.find(:all, :conditions => { :comments_count => 10 }, :limit => 5)
736   - ```
737   -
738   - should be rewritten in the new style which has existed since Rails 3:
739   -
740   - ```ruby
741   - Post.where(comments_count: 10).limit(5)
742   - ```
743   -
744   - Note that as an interim step, it is possible to rewrite the above as:
745   -
746   - ```ruby
747   - Post.scoped(:where => { :comments_count => 10 }, :limit => 5)
748   - ```
749   -
750   - This could save you a lot of work if there is a lot of old-style finder usage in your application.
751   -
752   - Calling `Post.scoped(options)` is a shortcut for `Post.scoped.merge(options)`. `Relation#merge` now accepts a hash of options, but they must be identical to the names of the equivalent finder method. These are mostly identical to the old-style finder option names, except in the following cases:
753   -
754   - ```
755   - :conditions becomes :where
756   - :include becomes :includes
757   - :extend becomes :extending
758   - ```
759   -
760   - The code to implement the deprecated features has been moved out to the `active_record_deprecated_finders` gem. This gem is a dependency of Active Record in Rails 4.0. It will no longer be a dependency from Rails 4.1, but if your app relies on the deprecated features then you can add it to your own Gemfile. It will be maintained by the Rails core team until Rails 5.0 is released.
761   -
762   -* Deprecate eager-evaluated scopes.
763   -
764   - Don't use this:
765   -
766   - ```ruby
767   - scope :red, where(color: 'red')
768   - default_scope where(color: 'red')
769   - ```
770   -
771   - Use this:
772   -
773   - ```ruby
774   - scope :red, -> { where(color: 'red') }
775   - default_scope { where(color: 'red') }
776   - ```
777   -
778   - The former has numerous issues. It is a common newbie gotcha to do the following:
779   -
780   - ```ruby
781   - scope :recent, where(published_at: Time.now - 2.weeks)
782   - ```
783   -
784   - Or a more subtle variant:
785   -
786   - ```ruby
787   - scope :recent, -> { where(published_at: Time.now - 2.weeks) }
788   - scope :recent_red, recent.where(color: 'red')
789   - ```
790   -
791   - Eager scopes are also very complex to implement within Active Record, and there are still bugs. For example, the following does not do what you expect:
792   -
793   - ```ruby
794   - scope :remove_conditions, except(:where)
795   - where(...).remove_conditions # => still has conditions
796   - ```
797   -
798   -* Added deprecation for the `:dependent => :restrict` association option.
799   -
800   -* Up until now `has_many` and `has_one, :dependent => :restrict` option raised a `DeleteRestrictionError` at the time of destroying the object. Instead, it will add an error on the model.
801   -
802   -* To fix this warning, make sure your code isn't relying on a `DeleteRestrictionError` and then add `config.active_record.dependent_restrict_raises = false` to your application config.
803   -
804   -* New rails application would be generated with the `config.active_record.dependent_restrict_raises = false` in the application config.
805   -
806   -* The migration generator now creates a join table with (commented) indexes every time the migration name contains the word "join_table".
807   -
808   -* `ActiveRecord::SessionStore` is removed from Rails 4.0 and is now a separate [gem](https://github.com/rails/activerecord-session_store).
809   -
810 110 Active Model
811 111 ------------
812 112
813   -* Changed `AM::Serializers::JSON.include_root_in_json` default value to false. Now, AM Serializers and AR objects have the same default behaviour.
814   -
815   - ```ruby
816   - class User < ActiveRecord::Base; end
817   -
818   - class Person
819   - include ActiveModel::Model
820   - include ActiveModel::AttributeMethods
821   - include ActiveModel::Serializers::JSON
822   -
823   - attr_accessor :name, :age
824   -
825   - def attributes
826   - instance_values
827   - end
828   - end
  113 +Please refer to the [Changelog](https://github.com/rails/rails/blob/master/activemodel/CHANGELOG.md) for detailed changes.
829 114
830   - user.as_json
831   - => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
832   - # root is not included
  115 +### Notable changes
833 116
834   - person.as_json
835   - => {"name"=>"Francesco", "age"=>22}
836   - # root is not included
837   - ```
  117 +* Add `ActiveModel::ForbiddenAttributesProtection`, a simple module to protect attributes from mass assignment when non-permitted attributes are passed.
838 118
839   -* Passing false hash values to `validates` will no longer enable the corresponding validators.
840   -
841   -* `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute`.
842   -
843   -* Added `ActiveModel::Model`, a mixin to make Ruby objects work with Action Pack out of the box. ([Pull Request](https://github.com/rails/rails/pull/5253))
844   -
845   -* `ActiveModel::Errors#to_json` supports a new parameter `:full_messages`.
846   -
847   -* Trims down the API by removing `valid?` and `errors.full_messages`.
  119 +* Added `ActiveModel::Model`, a mixin to make Ruby objects work with AP out of box.
848 120
849 121 ### Deprecations
850 122
851   -Active Resource
852   ----------------
853   -
854   -* Active Resource is removed from Rails 4.0 and is now a separate [gem](https://github.com/rails/activeresource).
855   -
856 123 Active Support
857 124 --------------
858 125
859   -* Add default values to all `ActiveSupport::NumberHelper` methods, to avoid errors with empty locales or missing values.
860   -
861   -* `Time#change` now works with time values with offsets other than UTC or the local time zone.
862   -
863   -* Add `Time#prev_quarter` and `Time#next_quarter` short-hands for `months_ago(3)` and `months_since(3)`.
864   -
865   -* Add `Time#last_week`, `Time#last_month`, `Time#last_year` as aliases for `Time#prev_week`, `Time#prev_month`, and `Time#prev_year`.
  126 +Please refer to the [Changelog](https://github.com/rails/rails/blob/master/activesupport/CHANGELOG.md) for detailed changes.
866 127
867   -* Add `Date#last_week`, `Date#last_month`, `Date#last_year` as aliases for `Date#prev_week`, `Date#prev_month`, and `Date#prev_year`.
  128 +### Notable changes
868 129
869   -* Remove obsolete and unused `require_association` method from dependencies.
  130 +* Replace deprecated `memcache-client` gem with `dalli` in ActiveSupport::Cache::MemCacheStore.
870 131
871   -* Add `:instance_accessor` option for `config_accessor`.
  132 +* Optimize ActiveSupport::Cache::Entry to reduce memory and processing overhead.
872 133
873   - ```ruby
874   - class User
875   - include ActiveSupport::Configurable
876   - config_accessor :allowed_access, instance_accessor: false
877   - end
  134 +* Inflections can now be defined per locale. `singularize` and `pluralize` accept locale as an extra argument.
878 135
879   - User.new.allowed_access = true # => NoMethodError
880   - User.new.allowed_access # => NoMethodError
881   - ```
  136 +* `Object#try` will now return nil instead of raise a NoMethodError if the receiving object does not implement the method, but you can still get the old behavior by using the new `Object#try!`.
882 137
883   -* `ActionView::Helpers::NumberHelper` methods have been moved to `ActiveSupport::NumberHelper` and are now available via `Numeric#to_s`.
884   -
885   -* `Numeric#to_s` now accepts the formatting options :phone, :currency, :percentage, :delimited, :rounded, :human, and :human_size.
886   -
887   -* Add `Hash#transform_keys`, `Hash#transform_keys!`, `Hash#deep_transform_keys` and `Hash#deep_transform_keys!`.
888   -
889   -* Changed xml type datetime to dateTime (with upper case letter T).
890   -
891   -* Add `:instance_accessor` option for `class_attribute`.
892   -
893   -* `constantize` now looks in the ancestor chain.
894   -
895   -* Add `Hash#deep_stringify_keys` and `Hash#deep_stringify_keys!` to convert all keys from a `Hash` instance into strings.
896   -
897   -* Add `Hash#deep_symbolize_keys` and `Hash#deep_symbolize_keys!` to convert all keys from a `Hash` instance into symbols.
898   -
899   -* `Object#try` can't call private methods.
900   -
901   -* AS::Callbacks#run_callbacks remove key argument.
  138 +### Deprecations
902 139
903   -* `deep_dup` works more expectedly now and duplicates also values in `Hash` instances and elements in `Array` instances.
  140 +* Deprecate `ActiveSupport::TestCase#pending` method, use `skip` from MiniTest instead.
904 141
905   -* Inflector no longer applies ice -> ouse to words like slice, police.
  142 +* ActiveSupport::Benchmarkable#silence has been deprecated due to its lack of thread safety. It will be removed without replacement in Rails 4.1.
906 143
907   -* Add `ActiveSupport::Deprecations.behavior = :silence` to completely ignore Rails runtime deprecations.
  144 +* `ActiveSupport::JSON::Variable` is deprecated. Define your own `#as_json` and `#encode_json` methods for custom JSON string literals.
908 145
909   -* Make `Module#delegate` stop using send - can no longer delegate to private methods.
  146 +* Deprecates the compatibility method Module#local_constant_names, use Module#local_constants instead (which returns symbols).
910 147
911   -* AS::Callbacks deprecate :rescuable option.
  148 +* BufferedLogger is deprecated. Use ActiveSupport::Logger, or the logger from Ruby stdlib.
912 149
913   -* Adds `Integer#ordinal` to get the ordinal suffix string of an integer.
914 150
915   -* AS::Callbacks :per_key option is no longer supported.
  151 +Action Pack
  152 +-----------
916 153
917   -* AS::Callbacks#define_callbacks add :skip_after_callbacks_if_terminated option.
  154 +Please refer to the [Changelog](https://github.com/rails/rails/blob/master/railties/CHANGELOG.md) for detailed changes.
918 155
919   -* Add html_escape_once to ERB::Util, and delegate escape_once tag helper to it.
  156 +### Notable changes
920 157
921   -* Remove `ActiveSupport::TestCase#pending` method, use `skip` instead.
  158 +### Deprecations
922 159
923   -* Deletes the compatibility method `Module#method_names`, use `Module#methods` from now on (which returns symbols).
924 160
925   -* Deletes the compatibility method `Module#instance_method_names`, use `Module#instance_methods` from now on (which returns symbols).
  161 +Active Record
  162 +-------------
926 163
927   -* Unicode database updated to 6.1.0.
  164 +Please refer to the [Changelog](https://github.com/rails/rails/blob/master/railties/CHANGELOG.md) for detailed changes.
928 165
929   -* Adds `encode_big_decimal_as_string` option to force JSON serialization of BigDecimals as numeric instead of wrapping them in strings for safety.
  166 +### Notable changes
930 167
931 168 ### Deprecations
932 169
933   -* `ActiveSupport::Callbacks`: deprecate usage of filter object with `#before` and `#after` methods as `around` callback.
934   -
935   -* `BufferedLogger` is deprecated. Use `ActiveSupport::Logger` or the `logger` from Ruby stdlib.
936   -
937   -* Deprecates the compatibility method `Module#local_constant_names` and use `Module#local_constants` instead (which returns symbols).
938   -
939 170 Credits
940 171 -------
941 172

0 comments on commit 9d3ce6c

Please sign in to comment.
Something went wrong with that request. Please try again.