From e9f04cdb6b3814b33ced289000e496416f894ee1 Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 13:54:24 -0500 Subject: [ci skip] Add return values to examples --- guides/source/active_record_querying.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 486e7b80ff..69d6205715 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1487,6 +1487,11 @@ If you'd like to use your own SQL to find records in a table you can use `find_b Client.find_by_sql("SELECT * FROM clients INNER JOIN orders ON clients.id = orders.client_id ORDER BY clients.created_at desc") +# => [ + #, + #, + # ... +] ``` `find_by_sql` provides you with a simple way of making custom calls to the database and retrieving instantiated objects. @@ -1496,7 +1501,11 @@ Client.find_by_sql("SELECT * FROM clients `find_by_sql` has a close relative called `connection#select_all`. `select_all` will retrieve objects from the database using custom SQL just like `find_by_sql` but will not instantiate them. Instead, you will get an array of hashes where each hash indicates a record. ```ruby -Client.connection.select_all("SELECT * FROM clients WHERE id = '1'") +Client.connection.select_all("SELECT first_name, created_at FROM clients WHERE id = '1'") +# => [ + {"first_name"=>"Rafael", "created_at"=>"2012-11-10 23:23:45.281189"}, + {"first_name"=>"Eileen", "created_at"=>"2013-12-09 11:22:35.221282"} +] ``` ### `pluck` -- cgit v1.2.3 From caa25e9fc3862ea036c81d7b7d58101b6bb79cb8 Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 14:03:00 -0500 Subject: [ci skip] Consolidate docs for `first` Add docs for `first` when provided a numerical argument. Since `first!` behaves exactly the same way but can raise an argument we can consolidate it in the `first` section. --- guides/source/active_record_querying.md | 56 +++++++++++++-------------------- 1 file changed, 21 insertions(+), 35 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 69d6205715..0d3a1dc948 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -132,7 +132,7 @@ TIP: The retrieved record may vary depending on the database engine. #### `first` -`Model.first` finds the first record ordered by the primary key. For example: +The `first` method finds the first record ordered by the primary key. For example: ```ruby client = Client.first @@ -145,7 +145,26 @@ The SQL equivalent of the above is: SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1 ``` -`Model.first` returns `nil` if no matching record is found and no exception will be raised. +The `first` method returns `nil` if no matching record is found and no exception will be raised. + +You can pass in a numerical argument to the `first` method to return up to that number of results. For example + +```ruby +client = Client.first(3) +# => [ + #, + #, + # +] +``` + +The SQL equivalent of the above is: + +```sql +SELECT * FROM clients ORDER BY clients.id ASC LIMIT 3 +``` + +The `first!` method behaves exactly like `first`, except that it will raise `ActiveRecord::RecordNotFound` if no matching record is found. #### `last` @@ -199,23 +218,6 @@ SELECT * FROM clients LIMIT 1 `Model.take!` raises `ActiveRecord::RecordNotFound` if no matching record is found. -#### `first!` - -`Model.first!` finds the first record ordered by the primary key. For example: - -```ruby -client = Client.first! -# => # -``` - -The SQL equivalent of the above is: - -```sql -SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1 -``` - -`Model.first!` raises `ActiveRecord::RecordNotFound` if no matching record is found. - #### `last!` `Model.last!` finds the last record ordered by the primary key. For example: @@ -287,22 +289,6 @@ The SQL equivalent of the above is: SELECT * FROM clients LIMIT 2 ``` -#### first - -`Model.first(limit)` finds the first number of records specified by `limit` ordered by primary key: - -```ruby -Client.first(2) -# => [#, - #] -``` - -The SQL equivalent of the above is: - -```sql -SELECT * FROM clients ORDER BY id ASC LIMIT 2 -``` - #### last `Model.last(limit)` finds the number of records specified by `limit` ordered by primary key in descending order: -- cgit v1.2.3 From 7d9c3ff55c288d277b20c69df4a61c505a99f90c Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 14:07:25 -0500 Subject: [ci skip] Consolidate docs for `find_by` Since `find_by!` behaves exactly the same way but can raise an argument we can consolidate it in the `find_by` section. --- guides/source/active_record_querying.md | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 0d3a1dc948..ecfc743642 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -185,7 +185,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 #### `find_by` -`Model.find_by` finds the first record matching some conditions. For example: +The `find_by` method finds the first record matching some conditions. For example: ```ruby Client.find_by first_name: 'Lifo' @@ -201,6 +201,19 @@ It is equivalent to writing: Client.where(first_name: 'Lifo').take ``` +The `find_by!` method behaves exactly like `find_by`, except that it will raise `ActiveRecord::RecordNotFound` if no matching record is found. For example: + +```ruby +Client.find_by! first_name: 'does not exist' +# => ActiveRecord::RecordNotFound +``` + +This is equivalent to writing: + +```ruby +Client.where(first_name: 'does not exist').take! +``` + #### `take!` `Model.take!` retrieves a record without any implicit ordering. For example: @@ -235,24 +248,6 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 `Model.last!` raises `ActiveRecord::RecordNotFound` if no matching record is found. -#### `find_by!` - -`Model.find_by!` finds the first record matching some conditions. It raises `ActiveRecord::RecordNotFound` if no matching record is found. For example: - -```ruby -Client.find_by! first_name: 'Lifo' -# => # - -Client.find_by! first_name: 'Jon' -# => ActiveRecord::RecordNotFound -``` - -It is equivalent to writing: - -```ruby -Client.where(first_name: 'Lifo').take! -``` - ### Retrieving Multiple Objects #### Using Multiple Primary Keys -- cgit v1.2.3 From d319ef851a5d5967271ed7169d6c5c1e028951c6 Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 14:16:49 -0500 Subject: [ci skip] Consolidate docs for `take` Add docs on what happens when a numerical argument is provided to take. Since `take!` behaves exactly the same way but can raise an argument we can consolidate it in the `take` section. --- guides/source/active_record_querying.md | 55 ++++++++++++--------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index ecfc743642..2533edc706 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -113,7 +113,7 @@ SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1 #### `take` -`Model.take` retrieves a record without any implicit ordering. For example: +The `take` method retrieves a record without any implicit ordering. For example: ```ruby client = Client.take @@ -126,7 +126,25 @@ The SQL equivalent of the above is: SELECT * FROM clients LIMIT 1 ``` -`Model.take` returns `nil` if no record is found and no exception will be raised. +The `take` method returns `nil` if no record is found and no exception will be raised. + +You can pass in a numerical argument to the `take` method to return up to that number of results. For example + +```ruby +client = Client.take(2) +# => [ + #, + # +] +``` + +The SQL equivalent of the above is: + +```sql +SELECT * FROM clients LIMIT 2 +``` + +The `take!` method behaves exactly like `take`, except that it will raise `ActiveRecord::RecordNotFound` if no matching record is found. TIP: The retrieved record may vary depending on the database engine. @@ -214,23 +232,6 @@ This is equivalent to writing: Client.where(first_name: 'does not exist').take! ``` -#### `take!` - -`Model.take!` retrieves a record without any implicit ordering. For example: - -```ruby -client = Client.take! -# => # -``` - -The SQL equivalent of the above is: - -```sql -SELECT * FROM clients LIMIT 1 -``` - -`Model.take!` raises `ActiveRecord::RecordNotFound` if no matching record is found. - #### `last!` `Model.last!` finds the last record ordered by the primary key. For example: @@ -268,22 +269,6 @@ SELECT * FROM clients WHERE (clients.id IN (1,10)) WARNING: `Model.find(array_of_primary_key)` will raise an `ActiveRecord::RecordNotFound` exception unless a matching record is found for **all** of the supplied primary keys. -#### take - -`Model.take(limit)` retrieves the first number of records specified by `limit` without any explicit ordering: - -```ruby -Client.take(2) -# => [#, - #] -``` - -The SQL equivalent of the above is: - -```sql -SELECT * FROM clients LIMIT 2 -``` - #### last `Model.last(limit)` finds the number of records specified by `limit` ordered by primary key in descending order: -- cgit v1.2.3 From d4fd0bd17709735ac91e434c94fe99429f078c6e Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 14:30:52 -0500 Subject: [ci skip] Consolidate docs for `last` Add docs on what happens when a numerical argument is provided to last. Since `last!` behaves exactly the same way but can raise an argument we can consolidate it in the `last` section. --- guides/source/active_record_querying.md | 37 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 2533edc706..a699a3dffe 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -186,7 +186,7 @@ The `first!` method behaves exactly like `first`, except that it will raise `Act #### `last` -`Model.last` finds the last record ordered by the primary key. For example: +The `last` method finds the last record ordered by the primary key. For example: ```ruby client = Client.last @@ -199,7 +199,26 @@ The SQL equivalent of the above is: SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 ``` -`Model.last` returns `nil` if no matching record is found and no exception will be raised. +The `last` method returns `nil` if no matching record is found and no exception will be raised. + +You can pass in a numerical argument to the `last` method to return up to that number of results. For example + +```ruby +client = Client.last(3) +# => [ + #, + #, + # +] +``` + +The SQL equivalent of the above is: + +```sql +SELECT * FROM clients ORDER BY clients.id DESC LIMIT 3 +``` + +The `last!` method behaves exactly like `last`, except that it will raise `ActiveRecord::RecordNotFound` if no matching record is found. #### `find_by` @@ -269,21 +288,7 @@ SELECT * FROM clients WHERE (clients.id IN (1,10)) WARNING: `Model.find(array_of_primary_key)` will raise an `ActiveRecord::RecordNotFound` exception unless a matching record is found for **all** of the supplied primary keys. -#### last - -`Model.last(limit)` finds the number of records specified by `limit` ordered by primary key in descending order: - -```ruby -Client.last(2) -# => [#, - #] -``` - -The SQL equivalent of the above is: -```sql -SELECT * FROM clients ORDER BY id DESC LIMIT 2 -``` ### Retrieving Multiple Objects in Batches -- cgit v1.2.3 From 63f4155596d1403dbf4972adc0d5877c1ea6d2b0 Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 14:38:16 -0500 Subject: [ci skip] Consolidate docs for `find` Put all options for overloading `find` in one section --- guides/source/active_record_querying.md | 44 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index a699a3dffe..0b6f40c129 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -93,9 +93,9 @@ The primary operation of `Model.find(options)` can be summarized as: Active Record provides several different ways of retrieving a single object. -#### Using a Primary Key +#### `find` -Using `Model.find(primary_key)`, you can retrieve the object corresponding to the specified _primary key_ that matches any supplied options. For example: +Using the `find` method, you can retrieve the object corresponding to the specified _primary key_ that matches any supplied options. For example: ```ruby # Find the client with primary key (id) 10. @@ -109,7 +109,23 @@ The SQL equivalent of the above is: SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1 ``` -`Model.find(primary_key)` will raise an `ActiveRecord::RecordNotFound` exception if no matching record is found. +The `find` method will raise an `ActiveRecord::RecordNotFound` exception if no matching record is found. + +You can also use this method to query for multiple objects. Call the `find` method and pass in an array of primary keys. The return will be an array containing all of the matching records for the supplied _primary keys_. For example: + +```ruby +# Find the clients with primary keys 1 and 10. +client = Client.find([1, 10]) # Or even Client.find(1, 10) +# => [#, #] +``` + +The SQL equivalent of the above is: + +```sql +SELECT * FROM clients WHERE (clients.id IN (1,10)) +``` + +WARNING: The `find` method will raise an `ActiveRecord::RecordNotFound` exception unless a matching record is found for **all** of the supplied primary keys. #### `take` @@ -268,28 +284,6 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 `Model.last!` raises `ActiveRecord::RecordNotFound` if no matching record is found. -### Retrieving Multiple Objects - -#### Using Multiple Primary Keys - -`Model.find(array_of_primary_key)` accepts an array of _primary keys_, returning an array containing all of the matching records for the supplied _primary keys_. For example: - -```ruby -# Find the clients with primary keys 1 and 10. -client = Client.find([1, 10]) # Or even Client.find(1, 10) -# => [#, #] -``` - -The SQL equivalent of the above is: - -```sql -SELECT * FROM clients WHERE (clients.id IN (1,10)) -``` - -WARNING: `Model.find(array_of_primary_key)` will raise an `ActiveRecord::RecordNotFound` exception unless a matching record is found for **all** of the supplied primary keys. - - - ### Retrieving Multiple Objects in Batches We often need to iterate over a large set of records, as when we send a newsletter to a large set of users, or when we export data. -- cgit v1.2.3 From f7e4362011ceb1317fd401125d48d7ccb9a1079c Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 14:46:33 -0500 Subject: [ci skip] Doc ability to chain in `find_each` Also use appropriate mailer syntax in the `find_each` block. --- guides/source/active_record_querying.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 0b6f40c129..311df3a953 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -309,7 +309,15 @@ The `find_each` method retrieves a batch of records and then yields _each_ recor ```ruby User.find_each do |user| - NewsLetter.weekly_deliver(user) + NewsMailer.weekly(user).deliver +end +``` + +To add conditions to a `find_each` operation you can chain other Active Record methods such as `where`: + +```ruby +User.where(weekly_subscriber: true).find_each do |user| + NewsMailer.weekly(user).deliver end ``` -- cgit v1.2.3 From 0f6b101e09d210cea2494c5d4225760f1951ea67 Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 14:57:10 -0500 Subject: [ci skip] Fix doc for except The example showed is `except`, however the method "documented" is `unstop`. Fix to align the docs to the example. --- guides/source/active_record_querying.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 311df3a953..2f7fe6fe98 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -675,9 +675,9 @@ This will return single order objects for each day, but only those that are orde Overriding Conditions --------------------- -### `unscope` +### `except` -You can specify certain conditions to be removed using the `unscope` method. For example: +You can specify certain conditions to be removed using the `except` method. For example: ```ruby Article.where('id > 10').limit(20).order('id asc').except(:order) @@ -688,12 +688,11 @@ The SQL that would be executed: ```sql SELECT * FROM articles WHERE id > 10 LIMIT 20 -# Original query without `unscope` +# Original query without `except` SELECT * FROM articles WHERE id > 10 ORDER BY id asc LIMIT 20 - ``` -You can additionally unscope specific where clauses. For example: +You can additionally call `unscope` to remove a specific where clauses. For example: ```ruby Article.where(id: 10, trashed: false).unscope(where: :id) -- cgit v1.2.3 From 9d74a298f1dd72beb337001c69b63fc76ef20457 Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 28 Jun 2014 15:05:05 -0500 Subject: [ci skip] remove invalid code from docs --- guides/source/active_record_querying.md | 2 -- 1 file changed, 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 2f7fe6fe98..aa206242c4 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -731,8 +731,6 @@ The `reorder` method overrides the default scope order. For example: ```ruby class Article < ActiveRecord::Base - .. - .. has_many :comments, -> { order('posted_at DESC') } end -- cgit v1.2.3 From 00aae7cb38a9d7029b1530bcf21a89ead80130a4 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 11 Jul 2014 02:15:00 -0700 Subject: Synced 4.2 release notes with the latest commits. Also reordered some of the items to put newer ones on top (same order as CHANGELOGs), which makes it easier to diff while we are still working on it. --- guides/source/4_2_release_notes.md | 107 +++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 27 deletions(-) (limited to 'guides/source') diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md index 8c5abb54ea..2729ca6588 100644 --- a/guides/source/4_2_release_notes.md +++ b/guides/source/4_2_release_notes.md @@ -62,8 +62,17 @@ Please refer to the [Changelog][railties] for detailed changes. * The `rails application` command has been removed without replacement. ([Pull Request](https://github.com/rails/rails/pull/11616)) +### Deprecations + +* Deprecated `Rails::Rack::LogTailer` without replacement. + ([Commit](https://github.com/rails/rails/commit/84a13e019e93efaa8994b3f8303d635a7702dbce)) + ### Notable changes +* Introduced `--skip-gems` option in the app generator to skip gems such as + `turbolinks` and `coffee-rails` that does not have their own specific flags. + ([Commit](https://github.com/rails/rails/commit/10565895805887d4faf004a6f71219da177f78b7)) + * Introduced `bin/setup` script to bootstrap an application. ([Pull Request](https://github.com/rails/rails/pull/15189)) @@ -97,6 +106,15 @@ Please refer to the [Changelog][action-pack] for detailed changes. ### Notable changes +* `render nothing: true` or rendering a `nil` body no longer add a single space + padding to the response body. + ([Pull Request](https://github.com/rails/rails/pull/14883)) + +* Introduced the `always_permitted_parameters` option to configure which + parameters are permitted globally. The default value of this configuration is + `['controller', 'action']`. + ([Pull Request](https://github.com/rails/rails/pull/15933)) + * The `*_filter` family methods has been removed from the documentation. Their usage are discouraged in favor of the `*_action` family methods: @@ -159,6 +177,10 @@ Please refer to the [Changelog][action-view] for detailed changes. ### Notable changes +* The form helpers no longer generate a `
` element with inline CSS around + the hidden fields. + ([Pull Request](https://github.com/rails/rails/pull/14738)) + Action Mailer ------------- @@ -167,6 +189,10 @@ Please refer to the [Changelog][action-mailer] for detailed changes. ### Notable changes +* Added the `show_previews` configuration option for enabling mailer previews + outside of the development environment. + ([Pull Request](https://github.com/rails/rails/pull/15970)) + Active Record ------------- @@ -177,6 +203,9 @@ for detailed changes. ### Removals +* Removed `cache_attributes` and friends. All attributes are cached. + ([Pull Request](https://github.com/rails/rails/pull/15429)) + * Removed deprecated method `ActiveRecord::Base.quoted_locking_column`. ([Pull Request](https://github.com/rails/rails/pull/15612)) @@ -184,9 +213,6 @@ for detailed changes. `proper_table_name` instance method on `ActiveRecord::Migration` instead. ([Pull Request](https://github.com/rails/rails/pull/15512)) -* Removed `cache_attributes` and friends. All attributes are cached. - ([Pull Request](https://github.com/rails/rails/pull/15429)) - * Removed unused `:timestamp` type. Transparently alias it to `:datetime` in all cases. Fixes inconsistencies when column types are sent outside of `ActiveRecord`, such as for XML Serialization. @@ -194,13 +220,19 @@ for detailed changes. ### Deprecations -* Deprecated returning `nil` from `column_for_attribute` when no column exists. - It will return a null object in Rails 5.0 - ([Pull Request](https://github.com/rails/rails/pull/15878)) +* Deprecated broken support for automatic detection of counter caches on + `has_many :through` associations. You should instead manually specify the + counter cache on the `has_many` and `belongs_to` associations for the through + records. + ([Pull Request](https://github.com/rails/rails/pull/15754)) * Deprecated `serialized_attributes` without replacement. ([Pull Request](https://github.com/rails/rails/pull/15704)) +* Deprecated returning `nil` from `column_for_attribute` when no column exists. + It will return a null object in Rails 5.0 + ([Pull Request](https://github.com/rails/rails/pull/15878)) + * Deprecated using `.joins`, `.preload` and `.eager_load` with associations that depends on the instance state (i.e. those defined with a scope that takes an argument) without replacement. @@ -216,21 +248,39 @@ for detailed changes. is not fully possible because the Ruby range does not support excluded beginnings. - The current solution of incrementing the beginning is not correct - and is now deprecated. For subtypes where we don't know how to increment - (e.g. `#succ` is not defined) it will raise an `ArgumentError` for ranges with - excluding beginnings. + The current solution of incrementing the beginning is not correct + and is now deprecated. For subtypes where we don't know how to increment + (e.g. `#succ` is not defined) it will raise an `ArgumentError` for ranges with + excluding beginnings. - ([Commit](https://github.com/rails/rails/commit/91949e48cf41af9f3e4ffba3e5eecf9b0a08bfc3)) - -* Deprecated broken support for automatic detection of counter caches on - `has_many :through` associations. You should instead manually specify the - counter cache on the `has_many` and `belongs_to` associations for the through - records. - ([Pull Request](https://github.com/rails/rails/pull/15754)) + ([Commit](https://github.com/rails/rails/commit/91949e48cf41af9f3e4ffba3e5eecf9b0a08bfc3)) ### Notable changes +* Added a `:required` option to singular associations, which defines a + presence validation on the association. + ([Pull Request](https://github.com/rails/rails/pull/16056)) + +* Introduced `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the + record is invalid. + ([Pull Request](https://github.com/rails/rails/pull/8639)) + +* `ActiveRecord::Base#reload` now behaves the same as `m = Model.find(m.id)`, + meaning that it no longer retains the extra attributes from custom `select`s. + ([Pull Request](https://github.com/rails/rails/pull/15866)) + +* Introduced the `bin/rake db:purge` task to empty the database for the current + environment. + ([Commit](https://github.com/rails/rails/commit/e2f232aba15937a4b9d14bd91e0392c6d55be58d)) + +* `ActiveRecord::Dirty` now detects in-place changes to mutable values. + Serialized attributes on ActiveRecord models will no longer save when + unchanged. This also works with other types such as string columns and + json columns on PostgreSQL. + (Pull Requests [1](https://github.com/rails/rails/pull/15674), + [2](https://github.com/rails/rails/pull/15786), + [3](https://github.com/rails/rails/pull/15788)) + * Added support for `#pretty_print` in `ActiveRecord::Base` objects. ([Pull Request](https://github.com/rails/rails/pull/15172)) @@ -259,9 +309,6 @@ for detailed changes. * Added support for user-created range types in PostgreSQL adapter. ([Commit](https://github.com/rails/rails/commit/4cb47167e747e8f9dc12b0ddaf82bdb68c03e032)) -* Added a `:required` option to singular associations, which defines a - presence validation on the association. - ([Pull Request](https://github.com/rails/rails/pull/16056)) Active Model ------------ @@ -275,6 +322,14 @@ Please refer to the [Changelog][active-model] for detailed changes. ### Notable changes +* Introduced `undo_changes` method in `ActiveModel::Dirty` to restore the + changed (dirty) attributes to their previous values. + ([Pull Request](https://github.com/rails/rails/pull/14861)) + +* `has_secure_password` now verifies that the given password is less than 72 + characters if validations are enabled. + ([Pull Request](https://github.com/rails/rails/pull/15708)) + * Introduced `#validate` as an alias for `#valid?`. ([Pull Request](https://github.com/rails/rails/pull/14456)) @@ -302,20 +357,18 @@ Please refer to the [Changelog][active-support] for detailed changes. ### Notable changes +* Added `Hash#transform_values` and `Hash#transform_values!` to simplify a + common pattern where the values of a hash must change, but the keys are left + the same. + ([Pull Request](https://github.com/rails/rails/pull/15819)) + * The `humanize` inflector helper now strips any leading underscores. ([Commit](https://github.com/rails/rails/commit/daaa21bc7d20f2e4ff451637423a25ff2d5e75c7)) -* Added `SecureRandom::uuid_v3` and `SecureRandom::uuid_v5`. - ([Pull Request](https://github.com/rails/rails/pull/12016)) - * Introduce `Concern#class_methods` as an alternative to `module ClassMethods`, as well as `Kernel#concern` to avoid the `module Foo; extend ActiveSupport::Concern; end` boilerplate. ([Commit](https://github.com/rails/rails/commit/b16c36e688970df2f96f793a759365b248b582ad)) -* Added `Hash#transform_values` and `Hash#transform_values!` to simplify a - common pattern where the values of a hash must change, but the keys are left - the same. - ([Pull Request](https://github.com/rails/rails/pull/15819)) Credits ------- -- cgit v1.2.3 From b76269a692d744d8d4d9206da1b837676eb603d8 Mon Sep 17 00:00:00 2001 From: Max Goldstein Date: Fri, 11 Jul 2014 09:07:34 -0400 Subject: [Guides] Sentence break for clarity [ci-skip] --- guides/source/active_record_validations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 7ec4ab312d..582bb240dd 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -910,8 +910,8 @@ end The easiest way to add custom validators for validating individual attributes is with the convenient `ActiveModel::EachValidator`. In this case, the custom validator class must implement a `validate_each` method which takes three -arguments: record, attribute and value which correspond to the instance, the -attribute to be validated and the value of the attribute in the passed +arguments: record, attribute, and value. These correspond to the instance, the +attribute to be validated, and the value of the attribute in the passed instance. ```ruby -- cgit v1.2.3 From 85f463f616b2504428b3dfdb12608bbf023f3758 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 12 Jul 2014 10:14:29 +0000 Subject: Revert "[ci skip] Fix doc for except" This reverts commit 0f6b101e09d210cea2494c5d4225760f1951ea67. Reason: It's better to let `unscope` be documented. We can add a separate section for `except`. --- guides/source/active_record_querying.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index aa206242c4..f9368a6a1a 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -675,9 +675,9 @@ This will return single order objects for each day, but only those that are orde Overriding Conditions --------------------- -### `except` +### `unscope` -You can specify certain conditions to be removed using the `except` method. For example: +You can specify certain conditions to be removed using the `unscope` method. For example: ```ruby Article.where('id > 10').limit(20).order('id asc').except(:order) @@ -688,11 +688,12 @@ The SQL that would be executed: ```sql SELECT * FROM articles WHERE id > 10 LIMIT 20 -# Original query without `except` +# Original query without `unscope` SELECT * FROM articles WHERE id > 10 ORDER BY id asc LIMIT 20 + ``` -You can additionally call `unscope` to remove a specific where clauses. For example: +You can additionally unscope specific where clauses. For example: ```ruby Article.where(id: 10, trashed: false).unscope(where: :id) -- cgit v1.2.3 From d97d8379eb036e3129cd2d80deb6a026f11cd3be Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 12 Jul 2014 10:21:00 +0000 Subject: fix mismatched example call [ci skip] --- guides/source/active_record_querying.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index f9368a6a1a..c9e265de08 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -680,7 +680,7 @@ Overriding Conditions You can specify certain conditions to be removed using the `unscope` method. For example: ```ruby -Article.where('id > 10').limit(20).order('id asc').except(:order) +Article.where('id > 10').limit(20).order('id asc').unscope(:order) ``` The SQL that would be executed: @@ -693,7 +693,7 @@ SELECT * FROM articles WHERE id > 10 ORDER BY id asc LIMIT 20 ``` -You can additionally unscope specific where clauses. For example: +You can also unscope specific `where` clauses. For example: ```ruby Article.where(id: 10, trashed: false).unscope(where: :id) -- cgit v1.2.3 From 04e1281990fd1d18d95c6b609690380711d0b48a Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Sun, 13 Jul 2014 02:28:25 +0530 Subject: Add link to minitest rdoc & github --- guides/source/testing.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 561fe2cf70..a416cd36b5 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -365,7 +365,7 @@ Ideally, you would like to include a test for everything which could possibly br By now you've caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned. There are a bunch of different types of assertions you can use. -Here's an extract of the assertions you can use with `minitest`, the default testing library used by Rails. The `[msg]` parameter is an optional string message you can specify to make your test failure messages clearer. It's not required. +Here's an extract of the assertions you can use with [`Minitest`](https://github.com/seattlerb/minitest), the default testing library used by Rails. The `[msg]` parameter is an optional string message you can specify to make your test failure messages clearer. It's not required. | Assertion | Purpose | | ---------------------------------------------------------------- | ------- | @@ -395,6 +395,8 @@ Here's an extract of the assertions you can use with `minitest`, the default tes | `assert_send( array, [msg] )` | Ensures that executing the method listed in `array[1]` on the object in `array[0]` with the parameters of `array[2 and up]` is true. This one is weird eh?| | `flunk( [msg] )` | Ensures failure. This is useful to explicitly mark a test that isn't finished yet.| +The above are subset of assertions that minitest supports. For an exhaustive & more up-to-date list, please check [Minitest API documentation](http://docs.seattlerb.org/minitest/), specifically [`Minitest::Assertions`](http://docs.seattlerb.org/minitest/Minitest/Assertions.html) + Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that's exactly what Rails does. It includes some specialized assertions to make your life easier. NOTE: Creating your own assertions is an advanced topic that we won't cover in this tutorial. -- cgit v1.2.3 From 9386ddfd40fcaddc0481ae2d331708247f10ba08 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Sun, 13 Jul 2014 17:23:32 -0700 Subject: Format pass on 4.2 release notes [ci skip] * Leave two blank lines between sections/packages for readibility. * Always indent bullet points with four spaces. This allows multi-paragraph points to align properly (see #16103), and it is the same as the format we already use in CHANGELOGs. Doing this consistently sets an easy precedent for future contributors to follow. * Always put the PR/commit link on its own line in the source. If the bullet point spans multiple paragraphs, put it on its own paragraph at the end. [Godfrey Chan & Juanito Fatas] --- guides/source/4_2_release_notes.md | 320 +++++++++++++++++++------------------ 1 file changed, 163 insertions(+), 157 deletions(-) (limited to 'guides/source') diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md index 2729ca6588..12db528b91 100644 --- a/guides/source/4_2_release_notes.md +++ b/guides/source/4_2_release_notes.md @@ -59,31 +59,32 @@ Please refer to the [Changelog][railties] for detailed changes. ### Removals -* The `rails application` command has been removed without replacement. - ([Pull Request](https://github.com/rails/rails/pull/11616)) +* The `rails application` command has been removed without replacement. + ([Pull Request](https://github.com/rails/rails/pull/11616)) ### Deprecations -* Deprecated `Rails::Rack::LogTailer` without replacement. - ([Commit](https://github.com/rails/rails/commit/84a13e019e93efaa8994b3f8303d635a7702dbce)) +* Deprecated `Rails::Rack::LogTailer` without replacement. + ([Commit](https://github.com/rails/rails/commit/84a13e019e93efaa8994b3f8303d635a7702dbce)) ### Notable changes -* Introduced `--skip-gems` option in the app generator to skip gems such as - `turbolinks` and `coffee-rails` that does not have their own specific flags. - ([Commit](https://github.com/rails/rails/commit/10565895805887d4faf004a6f71219da177f78b7)) +* Introduced `--skip-gems` option in the app generator to skip gems such as + `turbolinks` and `coffee-rails` that does not have their own specific flags. + ([Commit](https://github.com/rails/rails/commit/10565895805887d4faf004a6f71219da177f78b7)) -* Introduced `bin/setup` script to bootstrap an application. - ([Pull Request](https://github.com/rails/rails/pull/15189)) +* Introduced `bin/setup` script to bootstrap an application. + ([Pull Request](https://github.com/rails/rails/pull/15189)) -* Changed default value for `config.assets.digest` to `true` in development. - ([Pull Request](https://github.com/rails/rails/pull/15155)) +* Changed default value for `config.assets.digest` to `true` in development. + ([Pull Request](https://github.com/rails/rails/pull/15155)) -* Introduced an API to register new extensions for `rake notes`. - ([Pull Request](https://github.com/rails/rails/pull/14379)) +* Introduced an API to register new extensions for `rake notes`. + ([Pull Request](https://github.com/rails/rails/pull/14379)) + +* Introduced `Rails.gem_version` as a convenience method to return `Gem::Version.new(Rails.version)`. + ([Pull Request](https://github.com/rails/rails/pull/14101)) -* Introduced `Rails.gem_version` as a convenience method to return `Gem::Version.new(Rails.version)`. - ([Pull Request](https://github.com/rails/rails/pull/14101)) Action Pack ----------- @@ -92,8 +93,8 @@ Please refer to the [Changelog][action-pack] for detailed changes. ### Deprecations -* Deprecated support for setting the `:to` option of a router to a symbol or a - string that does not contain a `#` character: +* Deprecated support for setting the `:to` option of a router to a symbol or a + string that does not contain a `#` character: ```ruby get '/posts', to: MyRackApp => (No change necessary) @@ -106,17 +107,17 @@ Please refer to the [Changelog][action-pack] for detailed changes. ### Notable changes -* `render nothing: true` or rendering a `nil` body no longer add a single space - padding to the response body. - ([Pull Request](https://github.com/rails/rails/pull/14883)) +* `render nothing: true` or rendering a `nil` body no longer add a single + space padding to the response body. + ([Pull Request](https://github.com/rails/rails/pull/14883)) -* Introduced the `always_permitted_parameters` option to configure which - parameters are permitted globally. The default value of this configuration is - `['controller', 'action']`. - ([Pull Request](https://github.com/rails/rails/pull/15933)) +* Introduced the `always_permitted_parameters` option to configure which + parameters are permitted globally. The default value of this configuration + is `['controller', 'action']`. + ([Pull Request](https://github.com/rails/rails/pull/15933)) -* The `*_filter` family methods has been removed from the documentation. Their - usage are discouraged in favor of the `*_action` family methods: +* The `*_filter` family methods has been removed from the documentation. Their + usage are discouraged in favor of the `*_action` family methods: ``` after_filter => after_action @@ -141,22 +142,21 @@ Please refer to the [Changelog][action-pack] for detailed changes. (Commit [1](https://github.com/rails/rails/commit/6c5f43bab8206747a8591435b2aa0ff7051ad3de), [2](https://github.com/rails/rails/commit/489a8f2a44dc9cea09154ee1ee2557d1f037c7d4)) +* Added HTTP method `MKCALENDAR` from RFC-4791 + ([Pull Request](https://github.com/rails/rails/pull/15121)) -* Added HTTP method `MKCALENDAR` from RFC-4791 - ([Pull Request](https://github.com/rails/rails/pull/15121)) - -* `*_fragment.action_controller` notifications now include the controller and action name - in the payload. - ([Pull Request](https://github.com/rails/rails/pull/14137)) +* `*_fragment.action_controller` notifications now include the controller and action name + in the payload. + ([Pull Request](https://github.com/rails/rails/pull/14137)) -* Segments that are passed into URL helpers are now automatically escaped. - ([Commit](https://github.com/rails/rails/commit/5460591f0226a9d248b7b4f89186bd5553e7768f)) +* Segments that are passed into URL helpers are now automatically escaped. + ([Commit](https://github.com/rails/rails/commit/5460591f0226a9d248b7b4f89186bd5553e7768f)) -* Improved Routing Error page with fuzzy matching for route search. - ([Pull Request](https://github.com/rails/rails/pull/14619)) +* Improved Routing Error page with fuzzy matching for route search. + ([Pull Request](https://github.com/rails/rails/pull/14619)) -* Added option to disable logging of CSRF failures. - ([Pull Request](https://github.com/rails/rails/pull/14280)) +* Added option to disable logging of CSRF failures. + ([Pull Request](https://github.com/rails/rails/pull/14280)) Action View @@ -166,20 +166,20 @@ Please refer to the [Changelog][action-view] for detailed changes. ### Deprecations -* Deprecated `AbstractController::Base.parent_prefixes`. - Override `AbstractController::Base.local_prefixes` when you want to change - where to find views. - ([Pull Request](https://github.com/rails/rails/pull/15026)) +* Deprecated `AbstractController::Base.parent_prefixes`. + Override `AbstractController::Base.local_prefixes` when you want to change + where to find views. + ([Pull Request](https://github.com/rails/rails/pull/15026)) -* Deprecated `ActionView::Digestor#digest(name, format, finder, options = {})`, - arguments should be passed as a hash instead. - ([Pull Request](https://github.com/rails/rails/pull/14243)) +* Deprecated `ActionView::Digestor#digest(name, format, finder, options = {})`, + arguments should be passed as a hash instead. + ([Pull Request](https://github.com/rails/rails/pull/14243)) ### Notable changes -* The form helpers no longer generate a `
` element with inline CSS around - the hidden fields. - ([Pull Request](https://github.com/rails/rails/pull/14738)) +* The form helpers no longer generate a `
` element with inline CSS around + the hidden fields. + ([Pull Request](https://github.com/rails/rails/pull/14738)) Action Mailer @@ -189,9 +189,9 @@ Please refer to the [Changelog][action-mailer] for detailed changes. ### Notable changes -* Added the `show_previews` configuration option for enabling mailer previews - outside of the development environment. - ([Pull Request](https://github.com/rails/rails/pull/15970)) +* Added the `show_previews` configuration option for enabling mailer previews + outside of the development environment. + ([Pull Request](https://github.com/rails/rails/pull/15970)) Active Record @@ -203,111 +203,113 @@ for detailed changes. ### Removals -* Removed `cache_attributes` and friends. All attributes are cached. - ([Pull Request](https://github.com/rails/rails/pull/15429)) +* Removed `cache_attributes` and friends. All attributes are cached. + ([Pull Request](https://github.com/rails/rails/pull/15429)) -* Removed deprecated method `ActiveRecord::Base.quoted_locking_column`. - ([Pull Request](https://github.com/rails/rails/pull/15612)) +* Removed deprecated method `ActiveRecord::Base.quoted_locking_column`. + ([Pull Request](https://github.com/rails/rails/pull/15612)) -* Removed deprecated `ActiveRecord::Migrator.proper_table_name`. Use the - `proper_table_name` instance method on `ActiveRecord::Migration` instead. - ([Pull Request](https://github.com/rails/rails/pull/15512)) +* Removed deprecated `ActiveRecord::Migrator.proper_table_name`. Use the + `proper_table_name` instance method on `ActiveRecord::Migration` instead. + ([Pull Request](https://github.com/rails/rails/pull/15512)) -* Removed unused `:timestamp` type. Transparently alias it to `:datetime` - in all cases. Fixes inconsistencies when column types are sent outside of - `ActiveRecord`, such as for XML Serialization. - ([Pull Request](https://github.com/rails/rails/pull/15184)) +* Removed unused `:timestamp` type. Transparently alias it to `:datetime` + in all cases. Fixes inconsistencies when column types are sent outside of + `ActiveRecord`, such as for XML Serialization. + ([Pull Request](https://github.com/rails/rails/pull/15184)) ### Deprecations -* Deprecated broken support for automatic detection of counter caches on - `has_many :through` associations. You should instead manually specify the - counter cache on the `has_many` and `belongs_to` associations for the through - records. - ([Pull Request](https://github.com/rails/rails/pull/15754)) +* Deprecated broken support for automatic detection of counter caches on + `has_many :through` associations. You should instead manually specify the + counter cache on the `has_many` and `belongs_to` associations for the + through records. + ([Pull Request](https://github.com/rails/rails/pull/15754)) -* Deprecated `serialized_attributes` without replacement. - ([Pull Request](https://github.com/rails/rails/pull/15704)) +* Deprecated `serialized_attributes` without replacement. + ([Pull Request](https://github.com/rails/rails/pull/15704)) -* Deprecated returning `nil` from `column_for_attribute` when no column exists. - It will return a null object in Rails 5.0 - ([Pull Request](https://github.com/rails/rails/pull/15878)) +* Deprecated returning `nil` from `column_for_attribute` when no column + exists. It will return a null object in Rails 5.0 + ([Pull Request](https://github.com/rails/rails/pull/15878)) -* Deprecated using `.joins`, `.preload` and `.eager_load` with associations that - depends on the instance state (i.e. those defined with a scope that takes an - argument) without replacement. - ([Commit](https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1)) +* Deprecated using `.joins`, `.preload` and `.eager_load` with associations + that depends on the instance state (i.e. those defined with a scope that + takes an argument) without replacement. + ([Commit](https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1)) -* Deprecated passing Active Record objects to `.find` or `.exists?`. Call `#id` - on the objects first. - (Commit [1](https://github.com/rails/rails/commit/d92ae6ccca3bcfd73546d612efaea011270bd270), - [2](https://github.com/rails/rails/commit/d35f0033c7dec2b8d8b52058fb8db495d49596f7)) +* Deprecated passing Active Record objects to `.find` or `.exists?`. Call + `#id` on the objects first. + (Commit [1](https://github.com/rails/rails/commit/d92ae6ccca3bcfd73546d612efaea011270bd270), + [2](https://github.com/rails/rails/commit/d35f0033c7dec2b8d8b52058fb8db495d49596f7)) -* Deprecated half-baked support for PostgreSQL range values with excluding - beginnings. We currently map PostgreSQL ranges to Ruby ranges. This conversion - is not fully possible because the Ruby range does not support excluded - beginnings. +* Deprecated half-baked support for PostgreSQL range values with excluding + beginnings. We currently map PostgreSQL ranges to Ruby ranges. This conversion + is not fully possible because the Ruby range does not support excluded + beginnings. - The current solution of incrementing the beginning is not correct - and is now deprecated. For subtypes where we don't know how to increment - (e.g. `#succ` is not defined) it will raise an `ArgumentError` for ranges with - excluding beginnings. + The current solution of incrementing the beginning is not correct + and is now deprecated. For subtypes where we don't know how to increment + (e.g. `#succ` is not defined) it will raise an `ArgumentError` for ranges + with excluding beginnings. - ([Commit](https://github.com/rails/rails/commit/91949e48cf41af9f3e4ffba3e5eecf9b0a08bfc3)) + ([Commit](https://github.com/rails/rails/commit/91949e48cf41af9f3e4ffba3e5eecf9b0a08bfc3)) ### Notable changes -* Added a `:required` option to singular associations, which defines a - presence validation on the association. - ([Pull Request](https://github.com/rails/rails/pull/16056)) +* Added a `:required` option to singular associations, which defines a + presence validation on the association. + ([Pull Request](https://github.com/rails/rails/pull/16056)) -* Introduced `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the - record is invalid. - ([Pull Request](https://github.com/rails/rails/pull/8639)) +* Introduced `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the + record is invalid. + ([Pull Request](https://github.com/rails/rails/pull/8639)) -* `ActiveRecord::Base#reload` now behaves the same as `m = Model.find(m.id)`, - meaning that it no longer retains the extra attributes from custom `select`s. - ([Pull Request](https://github.com/rails/rails/pull/15866)) +* `ActiveRecord::Base#reload` now behaves the same as `m = Model.find(m.id)`, + meaning that it no longer retains the extra attributes from custom + `select`s. + ([Pull Request](https://github.com/rails/rails/pull/15866)) -* Introduced the `bin/rake db:purge` task to empty the database for the current - environment. - ([Commit](https://github.com/rails/rails/commit/e2f232aba15937a4b9d14bd91e0392c6d55be58d)) +* Introduced the `bin/rake db:purge` task to empty the database for the + current environment. + ([Commit](https://github.com/rails/rails/commit/e2f232aba15937a4b9d14bd91e0392c6d55be58d)) -* `ActiveRecord::Dirty` now detects in-place changes to mutable values. - Serialized attributes on ActiveRecord models will no longer save when - unchanged. This also works with other types such as string columns and - json columns on PostgreSQL. - (Pull Requests [1](https://github.com/rails/rails/pull/15674), - [2](https://github.com/rails/rails/pull/15786), - [3](https://github.com/rails/rails/pull/15788)) +* `ActiveRecord::Dirty` now detects in-place changes to mutable values. + Serialized attributes on ActiveRecord models will no longer save when + unchanged. This also works with other types such as string columns and json + columns on PostgreSQL. + (Pull Requests [1](https://github.com/rails/rails/pull/15674), + [2](https://github.com/rails/rails/pull/15786), + [3](https://github.com/rails/rails/pull/15788)) -* Added support for `#pretty_print` in `ActiveRecord::Base` objects. - ([Pull Request](https://github.com/rails/rails/pull/15172)) +* Added support for `#pretty_print` in `ActiveRecord::Base` objects. + ([Pull Request](https://github.com/rails/rails/pull/15172)) -* PostgreSQL and SQLite adapters no longer add a default limit of 255 characters - on string columns. - ([Pull Request](https://github.com/rails/rails/pull/14579)) +* PostgreSQL and SQLite adapters no longer add a default limit of 255 + characters on string columns. + ([Pull Request](https://github.com/rails/rails/pull/14579)) -* `sqlite3:///some/path` now resolves to the absolute system path `/some/path`. - For relative paths, use `sqlite3:some/path` instead. (Previously, `sqlite3:///some/path` - resolved to the relative path `some/path`. This behaviour was deprecated on - Rails 4.1.) - ([Pull Request](https://github.com/rails/rails/pull/14569)) +* `sqlite3:///some/path` now resolves to the absolute system path + `/some/path`. For relative paths, use `sqlite3:some/path` instead. + (Previously, `sqlite3:///some/path` resolved to the relative path + `some/path`. This behaviour was deprecated on Rails 4.1.) + ([Pull Request](https://github.com/rails/rails/pull/14569)) -* Introduced `#validate` as an alias for `#valid?`. - ([Pull Request](https://github.com/rails/rails/pull/14456)) +* Introduced `#validate` as an alias for `#valid?`. + ([Pull Request](https://github.com/rails/rails/pull/14456)) -* `#touch` now accepts multiple attributes to be touched at once. - ([Pull Request](https://github.com/rails/rails/pull/14423)) +* `#touch` now accepts multiple attributes to be touched at once. + ([Pull Request](https://github.com/rails/rails/pull/14423)) -* Added support for fractional seconds for MySQL 5.6 and above. - (Pull Request [1](https://github.com/rails/rails/pull/8240), [2](https://github.com/rails/rails/pull/14359)) +* Added support for fractional seconds for MySQL 5.6 and above. + (Pull Request [1](https://github.com/rails/rails/pull/8240), + [2](https://github.com/rails/rails/pull/14359)) -* Added support for the `citext` column type in PostgreSQL adapter. - ([Pull Request](https://github.com/rails/rails/pull/12523)) +* Added support for the `citext` column type in PostgreSQL adapter. + ([Pull Request](https://github.com/rails/rails/pull/12523)) -* Added support for user-created range types in PostgreSQL adapter. - ([Commit](https://github.com/rails/rails/commit/4cb47167e747e8f9dc12b0ddaf82bdb68c03e032)) +* Added support for user-created range types in PostgreSQL adapter. + ([Commit](https://github.com/rails/rails/commit/4cb47167e747e8f9dc12b0ddaf82bdb68c03e032)) Active Model @@ -317,21 +319,21 @@ Please refer to the [Changelog][active-model] for detailed changes. ### Removals -* Removed deprecated `Validator#setup` without replacement. - ([Pull Request](https://github.com/rails/rails/pull/15617)) +* Removed deprecated `Validator#setup` without replacement. + ([Pull Request](https://github.com/rails/rails/pull/15617)) ### Notable changes -* Introduced `undo_changes` method in `ActiveModel::Dirty` to restore the - changed (dirty) attributes to their previous values. - ([Pull Request](https://github.com/rails/rails/pull/14861)) +* Introduced `undo_changes` method in `ActiveModel::Dirty` to restore the + changed (dirty) attributes to their previous values. + ([Pull Request](https://github.com/rails/rails/pull/14861)) -* `has_secure_password` now verifies that the given password is less than 72 - characters if validations are enabled. - ([Pull Request](https://github.com/rails/rails/pull/15708)) +* `has_secure_password` now verifies that the given password is less than 72 + characters if validations are enabled. + ([Pull Request](https://github.com/rails/rails/pull/15708)) -* Introduced `#validate` as an alias for `#valid?`. - ([Pull Request](https://github.com/rails/rails/pull/14456)) +* Introduced `#validate` as an alias for `#valid?`. + ([Pull Request](https://github.com/rails/rails/pull/14456)) Active Support @@ -341,33 +343,37 @@ Please refer to the [Changelog][active-support] for detailed changes. ### Removals -* Removed deprecated `Numeric#ago`, `Numeric#until`, `Numeric#since`, - `Numeric#from_now`. ([Commit](https://github.com/rails/rails/commit/f1eddea1e3f6faf93581c43651348f48b2b7d8bb)) +* Removed deprecated `Numeric#ago`, `Numeric#until`, `Numeric#since`, + `Numeric#from_now`. + ([Commit](https://github.com/rails/rails/commit/f1eddea1e3f6faf93581c43651348f48b2b7d8bb)) -* Removed deprecated string based terminators for `ActiveSupport::Callbacks`. - ([Pull Request](https://github.com/rails/rails/pull/15100)) +* Removed deprecated string based terminators for `ActiveSupport::Callbacks`. + ([Pull Request](https://github.com/rails/rails/pull/15100)) ### Deprecations -* Deprecated `Class#superclass_delegating_accessor`, use `Class#class_attribute` - instead. ([Pull Request](https://github.com/rails/rails/pull/14271)) +* Deprecated `Class#superclass_delegating_accessor`, use + `Class#class_attribute` instead. + ([Pull Request](https://github.com/rails/rails/pull/14271)) -* Deprecated `ActiveSupport::SafeBuffer#prepend!` as `ActiveSupport::SafeBuffer#prepend` - now performs the same function. ([Pull Request](https://github.com/rails/rails/pull/14529)) +* Deprecated `ActiveSupport::SafeBuffer#prepend!` as + `ActiveSupport::SafeBuffer#prepend` now performs the same function. + ([Pull Request](https://github.com/rails/rails/pull/14529)) ### Notable changes -* Added `Hash#transform_values` and `Hash#transform_values!` to simplify a - common pattern where the values of a hash must change, but the keys are left - the same. - ([Pull Request](https://github.com/rails/rails/pull/15819)) +* Added `Hash#transform_values` and `Hash#transform_values!` to simplify a + common pattern where the values of a hash must change, but the keys are left + the same. + ([Pull Request](https://github.com/rails/rails/pull/15819)) -* The `humanize` inflector helper now strips any leading underscores. - ([Commit](https://github.com/rails/rails/commit/daaa21bc7d20f2e4ff451637423a25ff2d5e75c7)) +* The `humanize` inflector helper now strips any leading underscores. + ([Commit](https://github.com/rails/rails/commit/daaa21bc7d20f2e4ff451637423a25ff2d5e75c7)) -* Introduce `Concern#class_methods` as an alternative to `module ClassMethods`, - as well as `Kernel#concern` to avoid the `module Foo; extend ActiveSupport::Concern; end` - boilerplate. ([Commit](https://github.com/rails/rails/commit/b16c36e688970df2f96f793a759365b248b582ad)) +* Introduce `Concern#class_methods` as an alternative to + `module ClassMethods`, as well as `Kernel#concern` to avoid the + `module Foo; extend ActiveSupport::Concern; end` boilerplate. + ([Commit](https://github.com/rails/rails/commit/b16c36e688970df2f96f793a759365b248b582ad)) Credits @@ -375,8 +381,8 @@ Credits 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. +the many people who spent many hours making Rails the stable and robust +framework it is today. Kudos to all of them. [railties]: https://github.com/rails/rails/blob/4-2-stable/railties/CHANGELOG.md [action-pack]: https://github.com/rails/rails/blob/4-2-stable/actionpack/CHANGELOG.md -- cgit v1.2.3 From da6472c916be5645ea4d761e7cbf44d486ca07a8 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 15 Jul 2014 09:08:31 -0700 Subject: Document the change in `nil` handling for serialized attributes Also updated the test case to reflect that --- guides/source/upgrading_ruby_on_rails.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'guides/source') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 36cd505977..b3e4505fc0 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -52,6 +52,11 @@ Upgrading from Rails 4.1 to Rails 4.2 NOTE: This section is a work in progress. +### Serialized attributes + +When assigning `nil` to a serialized attribute, it will be saved to the database +as `NULL` instead of passing the `nil` value through the coder (e.g. `"null"` +when using the `JSON` coder). Upgrading from Rails 4.0 to Rails 4.1 ------------------------------------- -- cgit v1.2.3 From 41fb06fa47b0c11d6b943163ec1bc8ce9fd4d229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 15 Jul 2014 16:12:23 -0300 Subject: Deprecate `reset_#{attribute}` in favor of `restore_#{attribute}`. These methods may cause confusion with the `reset_changes` that behaves differently of them. Also rename undo_changes to restore_changes to match this new set of methods. --- guides/source/active_model_basics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index 1131a83c36..3eaeeff389 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -202,7 +202,7 @@ person.valid? # => raises ActiveModel::StrictValidationFa ### ActiveModel::Naming Naming adds a number of class methods which make the naming and routing -easier to manage. The module defines the `model_name` class method which +easier to manage. The module defines the `model_name` class method which will define a number of accessors using some `ActiveSupport::Inflector` methods. ```ruby @@ -220,4 +220,4 @@ Person.model_name.param_key # => "person" Person.model_name.i18n_key # => :person Person.model_name.route_key # => "people" Person.model_name.singular_route_key # => "person" -``` \ No newline at end of file +``` -- cgit v1.2.3 From cbc0c184614b85d8d6b06da93cbdabb8b48fa6a1 Mon Sep 17 00:00:00 2001 From: Jonas Baumann Date: Wed, 16 Jul 2014 11:41:25 +0200 Subject: document assert[_not]_empty, assert[_not]_includes, assert[_not]_predicate in testing guide. --- guides/source/testing.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 561fe2cf70..e780ad2c89 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -377,8 +377,12 @@ Here's an extract of the assertions you can use with `minitest`, the default tes | `assert_not_same( expected, actual, [msg] )` | Ensures that `expected.equal?(actual)` is false.| | `assert_nil( obj, [msg] )` | Ensures that `obj.nil?` is true.| | `assert_not_nil( obj, [msg] )` | Ensures that `obj.nil?` is false.| +| `assert_empty( obj, [msg] )` | Ensures that `obj` is `empty?`.| +| `assert_not_empty( obj, [msg] )` | Ensures that `obj` is not `empty?`.| | `assert_match( regexp, string, [msg] )` | Ensures that a string matches the regular expression.| | `assert_no_match( regexp, string, [msg] )` | Ensures that a string doesn't match the regular expression.| +| `assert_includes( collection, obj, [msg] )` | Ensures that `obj` is in `collection`.| +| `assert_not_includes( collection, obj, [msg] )` | Ensures that `obj` is not in `collection`.| | `assert_in_delta( expecting, actual, [delta], [msg] )` | Ensures that the numbers `expected` and `actual` are within `delta` of each other.| | `assert_not_in_delta( expecting, actual, [delta], [msg] )` | Ensures that the numbers `expected` and `actual` are not within `delta` of each other.| | `assert_throws( symbol, [msg] ) { block }` | Ensures that the given block throws the symbol.| @@ -392,6 +396,8 @@ Here's an extract of the assertions you can use with `minitest`, the default tes | `assert_not_respond_to( obj, symbol, [msg] )` | Ensures that `obj` does not respond to `symbol`.| | `assert_operator( obj1, operator, [obj2], [msg] )` | Ensures that `obj1.operator(obj2)` is true.| | `assert_not_operator( obj1, operator, [obj2], [msg] )` | Ensures that `obj1.operator(obj2)` is false.| +| `assert_predicate ( obj, predicate, [msg] )` | Ensures that `obj.predicate` is true, e.g. `assert_predicate str, :empty?`| +| `assert_not_predicate ( obj, predicate, [msg] )` | Ensures that `obj.predicate` is false, e.g. `assert_not_predicate str, :empty?`| | `assert_send( array, [msg] )` | Ensures that executing the method listed in `array[1]` on the object in `array[0]` with the parameters of `array[2 and up]` is true. This one is weird eh?| | `flunk( [msg] )` | Ensures failure. This is useful to explicitly mark a test that isn't finished yet.| -- cgit v1.2.3 From e96e840ede2a7400f3acc73ab819ff91de068a1d Mon Sep 17 00:00:00 2001 From: Jonas Baumann Date: Wed, 16 Jul 2014 12:00:58 +0200 Subject: link minitest assertions documentation. --- guides/source/testing.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index e780ad2c89..b2da25b19f 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -364,8 +364,13 @@ Ideally, you would like to include a test for everything which could possibly br By now you've caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned. -There are a bunch of different types of assertions you can use. -Here's an extract of the assertions you can use with `minitest`, the default testing library used by Rails. The `[msg]` parameter is an optional string message you can specify to make your test failure messages clearer. It's not required. +There are a bunch of different types of assertions you can use. Here's an +extract of the +[assertions](http://docs.seattlerb.org/minitest/Minitest/Assertions.html) you +can use with [minitest](https://github.com/seattlerb/minitest), the default +testing library used by Rails. The `[msg]` parameter is an optional string +message you can specify to make your test failure messages clearer. It's not +required. | Assertion | Purpose | | ---------------------------------------------------------------- | ------- | -- cgit v1.2.3 From 758ae373055b977892db3673dcd4cae58cdc98a8 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Wed, 16 Jul 2014 22:45:58 +0800 Subject: [ci skip] Use appropriate mailer syntax. Reference: https://github.com/rails/rails/commit/f7e4362011ceb1317fd401125d48d7ccb9a1079c --- guides/source/active_record_querying.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index c9e265de08..a0a2f31a63 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -293,7 +293,7 @@ This may appear straightforward: ```ruby # This is very inefficient when the users table has thousands of rows. User.all.each do |user| - NewsLetter.weekly_deliver(user) + NewsMailer.weekly(user).deliver end ``` @@ -333,7 +333,7 @@ The `:batch_size` option allows you to specify the number of records to be retri ```ruby User.find_each(batch_size: 5000) do |user| - NewsLetter.weekly_deliver(user) + NewsMailer.weekly(user).deliver end ``` @@ -345,7 +345,7 @@ For example, to send newsletters only to users with the primary key starting fro ```ruby User.find_each(start: 2000, batch_size: 5000) do |user| - NewsLetter.weekly_deliver(user) + NewsMailer.weekly(user).deliver end ``` -- cgit v1.2.3 From 59b93dfda7def9e949f700fdb4d71885a1b17f59 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Wed, 16 Jul 2014 23:12:13 +0800 Subject: [ci skip] Remove duplicated last! section. Reference: https://github.com/rails/rails/commit/d4fd0bd17709735ac91e434c94fe99429f078c6e cc @schneems --- guides/source/active_record_querying.md | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index a0a2f31a63..35467fe95b 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -267,23 +267,6 @@ This is equivalent to writing: Client.where(first_name: 'does not exist').take! ``` -#### `last!` - -`Model.last!` finds the last record ordered by the primary key. For example: - -```ruby -client = Client.last! -# => # -``` - -The SQL equivalent of the above is: - -```sql -SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 -``` - -`Model.last!` raises `ActiveRecord::RecordNotFound` if no matching record is found. - ### Retrieving Multiple Objects in Batches We often need to iterate over a large set of records, as when we send a newsletter to a large set of users, or when we export data. -- cgit v1.2.3 From f032ba528b905e654e062efcf2e6db61b66a0b2a Mon Sep 17 00:00:00 2001 From: Dave Jachimiak Date: Thu, 17 Jul 2014 09:07:08 -0400 Subject: Remove "profile and benchmark" line from command line guide The profiling and benchmarking commands are no longer built into Rails. --- guides/source/command_line.md | 1 - 1 file changed, 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/command_line.md b/guides/source/command_line.md index cb0228fa75..3a78c3bb3f 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -7,7 +7,6 @@ After reading this guide, you will know: * How to generate models, controllers, database migrations, and unit tests. * How to start a development server. * How to experiment with objects through an interactive shell. -* How to profile and benchmark your new creation. -------------------------------------------------------------------------------- -- cgit v1.2.3 From ba9fe6cf90c12e3f81861e795b1c7299c3315b74 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Fri, 18 Jul 2014 11:51:36 +0200 Subject: Follow-up to #16097 [ci skip] Even if this is not exactly the same, let's add a new-line character instead of two spaces. While it's specified in the Markdown specs that adding spaces at the end of the line creates a break-line tag, this is a brittle approach as people may remove them saving the file on certain editors. --- guides/source/asset_pipeline.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 84cda9222e..dd018c0da8 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -124,19 +124,22 @@ with a built-in helper. In the source the generated code looked like this: The query string strategy has several disadvantages: 1. **Not all caches will reliably cache content where the filename only differs by -query parameters** +query parameters** + [Steve Souders recommends](http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/), "...avoiding a querystring for cacheable resources". He found that in this case 5-20% of requests will not be cached. Query strings in particular do not work at all with some CDNs for cache invalidation. -2. **The file name can change between nodes in multi-server environments.** +2. **The file name can change between nodes in multi-server environments.** + The default query string in Rails 2.x is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request. -3. **Too much cache invalidation** +3. **Too much cache invalidation** + When static assets are deployed with each new release of code, the mtime (time of last modification) of _all_ these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed. -- cgit v1.2.3 From 132e3fdf80046d4e2def9494cb0d1e9212caf0cf Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Sun, 20 Jul 2014 18:30:27 +0800 Subject: [ci skip] Normalize all localhost linking. --- guides/source/getting_started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index ef97cda3bc..ae3e0a3946 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -909,7 +909,7 @@ And then finally, add the view for this action, located at ``` -Now if you go to `http://localhost:3000/articles` you will see a list of all the +Now if you go to you will see a list of all the articles that you have created. ### Adding links @@ -1105,7 +1105,7 @@ standout. Now you'll get a nice error message when saving an article without title when you attempt to do just that on the new article form -[(http://localhost:3000/articles/new)](http://localhost:3000/articles/new). +: ![Form With Errors](images/getting_started/form_with_errors.png) -- cgit v1.2.3 From 7464d00dd73c524011e784cdf30cbb55d1662e7b Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 21 Jul 2014 11:27:20 +0900 Subject: [ci skip] Fix code in Routing Guide --- guides/source/routing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/routing.md b/guides/source/routing.md index c8f8ba3044..7a7334f25b 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -681,7 +681,7 @@ You can also constrain a route based on any method on the [Request object](actio You specify a request-based constraint the same way that you specify a segment constraint: ```ruby -get 'photos', constraints: { subdomain: 'admin' } +get 'photos', to: 'photos#index', constraints: { subdomain: 'admin' } ``` You can also specify constraints in a block form: -- cgit v1.2.3 From 7021e66588e4392c3efae9550dfea5c5c320d134 Mon Sep 17 00:00:00 2001 From: Siddharth Bhagwan Date: Mon, 21 Jul 2014 17:39:20 +0530 Subject: Generator guide grammatical error fixed [ci skip] --- guides/source/generators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/generators.md b/guides/source/generators.md index 93fb5eece8..be64f1638d 100644 --- a/guides/source/generators.md +++ b/guides/source/generators.md @@ -35,7 +35,7 @@ $ bin/rails generate helper --help Creating Your First Generator ----------------------------- -Since Rails 3.0, generators are built on top of [Thor](https://github.com/erikhuda/thor). Thor provides powerful options parsing and a great API for manipulating files. For instance, let's build a generator that creates an initializer file named `initializer.rb` inside `config/initializers`. +Since Rails 3.0, generators are built on top of [Thor](https://github.com/erikhuda/thor). Thor provides powerful options for parsing and a great API for manipulating files. For instance, let's build a generator that creates an initializer file named `initializer.rb` inside `config/initializers`. The first step is to create a file at `lib/generators/initializer_generator.rb` with the following content: -- cgit v1.2.3 From ce14ebe6b4de3096e46fe0948c0fc4d4222adab2 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 22 Jul 2014 08:41:25 +0200 Subject: docs, add example for running a single test against core adapters. [ci skip] --- guides/source/contributing_to_ruby_on_rails.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'guides/source') diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index a8b959c725..0b05725623 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -318,6 +318,12 @@ You can also run any single test separately: $ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb ``` +To run a single test against all adapters, use: + +```bash +$ bundle exec rake TEST=test/cases/associations/has_many_associations_test.rb +``` + You can invoke `test_jdbcmysql`, `test_jdbcsqlite3` or `test_jdbcpostgresql` also. See the file `activerecord/RUNNING_UNIT_TESTS.rdoc` for information on running more targeted database tests, or the file `ci/travis.rb` for the test suite run by the continuous integration server. ### Warnings -- cgit v1.2.3 From 28b3180f496d597d0a0017a4ab600d4da0d50224 Mon Sep 17 00:00:00 2001 From: Akshay Vishnoi Date: Tue, 22 Jul 2014 19:19:32 +0530 Subject: Fixes #16255 [ci skip] --- guides/source/getting_started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index ef97cda3bc..656d74ef06 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -120,7 +120,7 @@ To verify that you have everything installed correctly, you should be able to run the following: ```bash -$ bin/rails --version +$ rails --version ``` If it says something like "Rails 4.2.0", you are ready to continue. -- cgit v1.2.3 From d0af90592540225080d03ea2384da759f18620ff Mon Sep 17 00:00:00 2001 From: Tony Jian Date: Mon, 21 Jul 2014 16:48:37 +0800 Subject: `create` return an active record object with erros instead of false when validation fails. [skip ci] --- guides/source/active_record_basics.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md index 21022f1abb..eff93ce41d 100644 --- a/guides/source/active_record_basics.md +++ b/guides/source/active_record_basics.md @@ -310,10 +310,10 @@ models and validate that an attribute value is not empty, is unique and not already in the database, follows a specific format and many more. Validation is a very important issue to consider when persisting to the database, so -the methods `create`, `save` and `update` take it into account when +the methods `save` and `update` take it into account when running: they return `false` when validation fails and they didn't actually perform any operation on the database. All of these have a bang counterpart (that -is, `create!`, `save!` and `update!`), which are stricter in that +is, `save!` and `update!`), which are stricter in that they raise the exception `ActiveRecord::RecordInvalid` if validation fails. A quick example to illustrate: @@ -322,8 +322,9 @@ class User < ActiveRecord::Base validates :name, presence: true end -User.create # => false -User.create! # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank +user = User.new +user.save # => false +user.save! # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank ``` You can learn more about validations in the [Active Record Validations -- cgit v1.2.3 From 2e679ac262726045e4273f04ce8a55d97f621dd3 Mon Sep 17 00:00:00 2001 From: Akshay Vishnoi Date: Thu, 24 Jul 2014 11:39:41 +0530 Subject: Calling require_self twice in css raises Sprockets::ArgumentError exception [ci skip] --- guides/source/asset_pipeline.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index dd018c0da8..e31cefa5bb 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -493,8 +493,7 @@ The directives that work in JavaScript files also work in stylesheets one, requiring all stylesheets from the current directory. In this example, `require_self` is used. This puts the CSS contained within the -file (if any) at the precise location of the `require_self` call. If -`require_self` is called more than once, only the last call is respected. +file (if any) at the precise location of the `require_self` call. NOTE. If you want to use multiple Sass files, you should generally use the [Sass `@import` rule](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#import) instead of these Sprockets directives. When using Sprockets directives, Sass files exist within -- cgit v1.2.3 From 0f9118ab6fc1376189777d6b6fbaa46d24d4ec74 Mon Sep 17 00:00:00 2001 From: Matt Warren Date: Tue, 22 Jul 2014 09:27:57 -0600 Subject: adding indexes on tables in migration scripts missed one migration script in last commit remove some empty lines using the belongs_to index option to be more concise --- guides/source/association_basics.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 7e99da3f6d..daf4113b66 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -105,7 +105,7 @@ class CreateOrders < ActiveRecord::Migration end create_table :orders do |t| - t.belongs_to :customer + t.belongs_to :customer, index: true t.datetime :order_date t.timestamps end @@ -136,7 +136,7 @@ class CreateSuppliers < ActiveRecord::Migration end create_table :accounts do |t| - t.belongs_to :supplier + t.belongs_to :supplier, index: true t.string :account_number t.timestamps end @@ -169,7 +169,7 @@ class CreateCustomers < ActiveRecord::Migration end create_table :orders do |t| - t.belongs_to :customer + t.belongs_to :customer, index:true t.datetime :order_date t.timestamps end @@ -216,8 +216,8 @@ class CreateAppointments < ActiveRecord::Migration end create_table :appointments do |t| - t.belongs_to :physician - t.belongs_to :patient + t.belongs_to :physician, index: true + t.belongs_to :patient, index: true t.datetime :appointment_date t.timestamps end @@ -295,13 +295,13 @@ class CreateAccountHistories < ActiveRecord::Migration end create_table :accounts do |t| - t.belongs_to :supplier + t.belongs_to :supplier, index: true t.string :account_number t.timestamps end create_table :account_histories do |t| - t.belongs_to :account + t.belongs_to :account, index: true t.integer :credit_rating t.timestamps end @@ -341,8 +341,8 @@ class CreateAssembliesAndParts < ActiveRecord::Migration end create_table :assemblies_parts, id: false do |t| - t.belongs_to :assembly - t.belongs_to :part + t.belongs_to :assembly, index: true + t.belongs_to :part, index: true end end end @@ -379,6 +379,8 @@ class CreateSuppliers < ActiveRecord::Migration t.string :account_number t.timestamps end + + add_index :accounts, :supplier_id end end ``` @@ -455,6 +457,8 @@ class CreatePictures < ActiveRecord::Migration t.string :imageable_type t.timestamps end + + add_index :pictures, :imageable_id end end ``` @@ -466,7 +470,7 @@ class CreatePictures < ActiveRecord::Migration def change create_table :pictures do |t| t.string :name - t.references :imageable, polymorphic: true + t.references :imageable, polymorphic: true, index: true t.timestamps end end @@ -496,7 +500,7 @@ In your migrations/schema, you will add a references column to the model itself. class CreateEmployees < ActiveRecord::Migration def change create_table :employees do |t| - t.references :manager + t.references :manager, index: true t.timestamps end end @@ -561,6 +565,8 @@ class CreateOrders < ActiveRecord::Migration t.string :order_number t.integer :customer_id end + + add_index :orders, :customer_id end end ``` @@ -594,6 +600,9 @@ class CreateAssembliesPartsJoinTable < ActiveRecord::Migration t.integer :assembly_id t.integer :part_id end + + add_index :assemblies_parts, :assembly_id + add_index :assemblies_parts, :part_id end end ``` -- cgit v1.2.3 From 9c8826bcd2238d73e904e9ddc2bc7a779716318b Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 25 Jul 2014 23:44:05 +0400 Subject: [ci skip] Mention the change in nil handling for serialized attributes in "Upgrading from Rails 3.2 to Rails 4.0" --- guides/source/upgrading_ruby_on_rails.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'guides/source') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index b3e4505fc0..2a7b6a10a9 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -592,6 +592,9 @@ Rails 4.0 no longer supports loading plugins from `vendor/plugins`. You must rep * Rails 4.0 has changed `serialized_attributes` and `attr_readonly` to class methods only. You shouldn't use instance methods since it's now deprecated. You should change them to use class methods, e.g. `self.serialized_attributes` to `self.class.serialized_attributes`. +* When using the default coder, assigning `nil` to a serialized attribute will save it +to the database as `NULL` instead of passing the `nil` value through YAML (`"--- \n...\n"`). + * Rails 4.0 has removed `attr_accessible` and `attr_protected` feature in favor of Strong Parameters. You can use the [Protected Attributes gem](https://github.com/rails/protected_attributes) for a smooth upgrade path. * If you are not using Protected Attributes, you can remove any options related to -- cgit v1.2.3 From 4bfd0cef5bc0e6c052f8683ac0510845b7748a72 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Sat, 26 Jul 2014 22:34:56 +0400 Subject: [ci skip] Clarify the "Serialized Attributes" section Mention that the change in nil handling for serialized attributes affects custom coders. --- guides/source/upgrading_ruby_on_rails.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 2a7b6a10a9..0b8db49ef8 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -54,7 +54,8 @@ NOTE: This section is a work in progress. ### Serialized attributes -When assigning `nil` to a serialized attribute, it will be saved to the database +When using a custom coder (e.g. `serialize :metadata, JSON`), +assigning `nil` to a serialized attribute will save it to the database as `NULL` instead of passing the `nil` value through the coder (e.g. `"null"` when using the `JSON` coder). -- cgit v1.2.3 From 3d4233004814ccc183436df604bef563bfad21a1 Mon Sep 17 00:00:00 2001 From: Deepender Singla Date: Tue, 29 Jul 2014 22:48:50 +0530 Subject: Get request should not write to database note added. [skip ci] --- guides/source/routing.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source') diff --git a/guides/source/routing.md b/guides/source/routing.md index 7a7334f25b..c56be7cc12 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -645,6 +645,8 @@ match 'photos', to: 'photos#show', via: :all NOTE: Routing both `GET` and `POST` requests to a single action has security implications. In general, you should avoid routing all verbs to an action unless you have a good reason to. +NOTE: 'GET' in Rails doesn't check for CSRF token. You should never write to the database from 'GET' requests, for more information see the [security guide] (security.html#csrf-countermeasures) on CSRF countermeasures. + ### Segment Constraints You can use the `:constraints` option to enforce a format for a dynamic segment: -- cgit v1.2.3 From a240ad0c89915d1ddc8aca4dcee0dd084502c72c Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Tue, 29 Jul 2014 10:28:56 -0700 Subject: :nail_care: from #16329 [ci skip] --- guides/source/routing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/routing.md b/guides/source/routing.md index c56be7cc12..af8c1bbcc4 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -645,7 +645,7 @@ match 'photos', to: 'photos#show', via: :all NOTE: Routing both `GET` and `POST` requests to a single action has security implications. In general, you should avoid routing all verbs to an action unless you have a good reason to. -NOTE: 'GET' in Rails doesn't check for CSRF token. You should never write to the database from 'GET' requests, for more information see the [security guide] (security.html#csrf-countermeasures) on CSRF countermeasures. +NOTE: 'GET' in Rails won't check for CSRF token. You should never write to the database from 'GET' requests, for more information see the [security guide](security.html#csrf-countermeasures) on CSRF countermeasures. ### Segment Constraints -- cgit v1.2.3 From 2bbcca004cc232cef868cd0e301f274ce5638df0 Mon Sep 17 00:00:00 2001 From: "@schneems and @sgrif" Date: Thu, 19 Jun 2014 17:26:29 -0500 Subject: Deprecate `*_path` methods in mailers Email does not support relative links since there is no implicit host. Therefore all links inside of emails must be fully qualified URLs. All path helpers are now deprecated. When removed, the error will give early indication to developers to use `*_url` methods instead. Currently if a developer uses a `*_path` helper, their tests and `mail_view` will not catch the mistake. The only way to see the error is by sending emails in production. Preventing sending out emails with non-working path's is the desired end goal of this PR. Currently path helpers are mixed-in to controllers (the ActionMailer::Base acts as a controller). All `*_url` and `*_path` helpers are made available through the same module. This PR separates this behavior into two modules so we can extend the `*_path` methods to add a Deprecation to them. Once deprecated we can use this same area to raise a NoMethodError and add an informative message directing the developer to use `*_url` instead. The module with warnings is only mixed in when a controller returns false from the newly added `supports_relative_path?`. Paired @sgrif & @schneems --- guides/source/action_mailer_basics.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'guides/source') diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index cb1c1c653d..9ad9319255 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -414,6 +414,22 @@ globally in `config/application.rb`: config.action_mailer.default_url_options = { host: 'example.com' } ``` +Because of this behavior you cannot use any of the `*_path` helpers inside of +an email. Instead you will need to use the associated `*_url` helper. For example +instead of using + +``` +<%= link_to 'welcome', welcome_path %> +``` + +You will need to use: + +``` +<%= link_to 'welcome', welcome_url %> +``` + +By using the full URL, your links will now work in your emails. + #### generating URLs with `url_for` You need to pass the `only_path: false` option when using `url_for`. This will -- cgit v1.2.3 From dc1a6614dca69a8ec7a368c5a0d7bc32660c1c1d Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 2 Aug 2014 15:48:37 -0500 Subject: [ci skip] fix markdown --- guides/source/configuring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 13020fb286..6e897d1714 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -137,7 +137,7 @@ numbers. New applications filter out passwords by adding the following `config.f * `config.assets.enabled` a flag that controls whether the asset pipeline is enabled. It is set to true by default. -*`config.assets.raise_runtime_errors`* Set this flag to `true` to enable additional runtime error checking. Recommended in `config/environments/development.rb` to minimize unexpected behavior when deploying to `production`. +* `config.assets.raise_runtime_errors`* Set this flag to `true` to enable additional runtime error checking. Recommended in `config/environments/development.rb` to minimize unexpected behavior when deploying to `production`. * `config.assets.compress` a flag that enables the compression of compiled assets. It is explicitly set to true in `config/environments/production.rb`. -- cgit v1.2.3 From 097b2101897af447591d00fb2809d91894572b87 Mon Sep 17 00:00:00 2001 From: Stefan Kanev Date: Thu, 31 Jul 2014 12:05:07 +0200 Subject: Add an after_bundle callback in Rails templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The template runs before the generation of binstubs – this does not allow to write one, that makes an initial commit to version control. It is solvable by adding an after_bundle callback. --- guides/source/rails_application_templates.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/rails_application_templates.md b/guides/source/rails_application_templates.md index 0bd608c007..7a3bd35a22 100644 --- a/guides/source/rails_application_templates.md +++ b/guides/source/rails_application_templates.md @@ -38,9 +38,11 @@ generate(:scaffold, "person name:string") route "root to: 'people#index'" rake("db:migrate") -git :init -git add: "." -git commit: %Q{ -m 'Initial commit' } +after_bundle do + git :init + git add: "." + git commit: %Q{ -m 'Initial commit' } +end ``` The following sections outline the primary methods provided by the API: @@ -228,6 +230,22 @@ git add: "." git commit: "-a -m 'Initial commit'" ``` +### after_bundle(&block) + +Registers a callback to be executed after bundler and binstub generation have +run. Useful for adding the binstubs to version control: + +```ruby +after_bundle do + git :init + git add: '.' + git commit: "-a -m 'Initial commit'" +end +``` + +The callbacks gets executed even if `--skip-bundle` and/or `--skip-spring` has +been passed. + Advanced Usage -------------- -- cgit v1.2.3 From c9469c0d01711bc7105381f452a99f7730c281b4 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 3 Aug 2014 10:32:04 +0900 Subject: [ci skip] Remove "Machinist" from testing guide --- guides/source/testing.md | 1 - 1 file changed, 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 4ded7818b5..fe13c74745 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -1057,7 +1057,6 @@ The built-in `minitest` based testing is not the only way to test Rails applicat * [NullDB](http://avdi.org/projects/nulldb/), a way to speed up testing by avoiding database use. * [Factory Girl](https://github.com/thoughtbot/factory_girl/tree/master), a replacement for fixtures. -* [Machinist](https://github.com/notahat/machinist/tree/master), another replacement for fixtures. * [Fixture Builder](https://github.com/rdy/fixture_builder), a tool that compiles Ruby factories into fixtures before a test run. * [MiniTest::Spec Rails](https://github.com/metaskills/minitest-spec-rails), use the MiniTest::Spec DSL within your rails tests. * [Shoulda](http://www.thoughtbot.com/projects/shoulda), an extension to `test/unit` with additional helpers, macros, and assertions. -- cgit v1.2.3 From 1f72ab3addd6ba9bd4508d2a666c545ec2fda6d9 Mon Sep 17 00:00:00 2001 From: Aditya Kapoor Date: Sun, 3 Aug 2014 10:13:38 +0530 Subject: [ci skip] add tip for uglifier in execjs error --- guides/source/getting_started.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 656d74ef06..6c75edf89d 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -191,14 +191,15 @@ following in the `blog` directory: $ bin/rails server ``` -TIP: Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the -absence of a runtime will give you an `execjs` error. Usually Mac OS X and -Windows come with a JavaScript runtime installed. Rails adds the `therubyracer` -gem to the generated `Gemfile` in a commented line for new apps and you can -uncomment if you need it. `therubyrhino` is the recommended runtime for JRuby -users and is added by default to the `Gemfile` in apps generated under JRuby. -You can investigate about all the supported runtimes at -[ExecJS](https://github.com/sstephenson/execjs#readme). +TIP: Compiling CoffeeScript and JavaScript asset compression requires you +have a JavaScript runtime available on your system, in the absence +of a runtime you will see an `execjs` error during asset compilation. +Usually Mac OS X and Windows come with a JavaScript runtime installed. +Rails adds the `therubyracer` gem to the generated `Gemfile` in a +commented line for new apps and you can uncomment if you need it. +`therubyrhino` is the recommended runtime for JRuby users and is added by +default to the `Gemfile` in apps generated under JRuby. You can investigate +about all the supported runtimes at [ExecJS](https://github.com/sstephenson/execjs#readme). This will fire up WEBrick, a web server distributed with Ruby by default. To see your application in action, open a browser window and navigate to -- cgit v1.2.3 From 206347fd3e33ccf581593a32186e4375639ff43d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 3 Aug 2014 15:12:05 -0700 Subject: Update docs to reflect that helper stubs are no longer generated --- guides/source/command_line.md | 4 ---- guides/source/engines.md | 4 ---- guides/source/generators.md | 4 ---- guides/source/getting_started.md | 3 --- guides/source/testing.md | 12 ++---------- 5 files changed, 2 insertions(+), 25 deletions(-) (limited to 'guides/source') diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 3a78c3bb3f..a074b849c6 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -149,8 +149,6 @@ $ bin/rails generate controller Greetings hello create test/controllers/greetings_controller_test.rb invoke helper create app/helpers/greetings_helper.rb - invoke test_unit - create test/helpers/greetings_helper_test.rb invoke assets invoke coffee create app/assets/javascripts/greetings.js.coffee @@ -236,8 +234,6 @@ $ bin/rails generate scaffold HighScore game:string score:integer create test/controllers/high_scores_controller_test.rb invoke helper create app/helpers/high_scores_helper.rb - invoke test_unit - create test/helpers/high_scores_helper_test.rb invoke jbuilder create app/views/high_scores/index.json.jbuilder create app/views/high_scores/show.json.jbuilder diff --git a/guides/source/engines.md b/guides/source/engines.md index a5f8ee27b8..e9cce3f159 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -322,8 +322,6 @@ invoke test_unit create test/controllers/blorgh/articles_controller_test.rb invoke helper create app/helpers/blorgh/articles_helper.rb -invoke test_unit -create test/helpers/blorgh/articles_helper_test.rb invoke assets invoke js create app/assets/javascripts/blorgh/articles.js @@ -560,8 +558,6 @@ invoke test_unit create test/controllers/blorgh/comments_controller_test.rb invoke helper create app/helpers/blorgh/comments_helper.rb -invoke test_unit -create test/helpers/blorgh/comments_helper_test.rb invoke assets invoke js create app/assets/javascripts/blorgh/comments.js diff --git a/guides/source/generators.md b/guides/source/generators.md index be64f1638d..5e88fa0c70 100644 --- a/guides/source/generators.md +++ b/guides/source/generators.md @@ -191,8 +191,6 @@ $ bin/rails generate scaffold User name:string create test/controllers/users_controller_test.rb invoke helper create app/helpers/users_helper.rb - invoke test_unit - create test/helpers/users_helper_test.rb invoke jbuilder create app/views/users/index.json.jbuilder create app/views/users/show.json.jbuilder @@ -387,8 +385,6 @@ $ bin/rails generate scaffold Comment body:text create test/controllers/comments_controller_test.rb invoke my_helper create app/helpers/comments_helper.rb - invoke shoulda - create test/helpers/comments_helper_test.rb invoke jbuilder create app/views/comments/index.json.jbuilder create app/views/comments/show.json.jbuilder diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 94711b0a5d..1f91352c82 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -257,8 +257,6 @@ invoke test_unit create test/controllers/welcome_controller_test.rb invoke helper create app/helpers/welcome_helper.rb -invoke test_unit -create test/helpers/welcome_helper_test.rb invoke assets invoke coffee create app/assets/javascripts/welcome.js.coffee @@ -1637,7 +1635,6 @@ This creates six files and one empty directory: | app/views/comments/ | Views of the controller are stored here | | test/controllers/comments_controller_test.rb | The test for the controller | | app/helpers/comments_helper.rb | A view helper file | -| test/helpers/comments_helper_test.rb | The test for the helper | | app/assets/javascripts/comment.js.coffee | CoffeeScript for the controller | | app/assets/stylesheets/comment.css.scss | Cascading style sheet for the controller | diff --git a/guides/source/testing.md b/guides/source/testing.md index fe13c74745..3e12afc000 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -1014,17 +1014,9 @@ Testing helpers In order to test helpers, all you need to do is check that the output of the helper method matches what you'd expect. Tests related to the helpers are -located under the `test/helpers` directory. Rails provides a generator which -generates both the helper and the test file: +located under the `test/helpers` directory. -```bash -$ bin/rails generate helper User - create app/helpers/user_helper.rb - invoke test_unit - create test/helpers/user_helper_test.rb -``` - -The generated test file contains the following code: +A helper test looks like so: ```ruby require 'test_helper' -- cgit v1.2.3 From 611849772dd66c2e4d005dcfe153f7ce79a8a7db Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 3 Aug 2014 15:48:14 -0700 Subject: Pull in the custom configuration concept from dhh/custom_configuration --- guides/source/configuring.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 6e897d1714..305adb0608 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -996,3 +996,24 @@ If you get the above error, you might want to increase the size of connection pool by incrementing the `pool` option in `database.yml` NOTE. If you are running in a multi-threaded environment, there could be a chance that several threads may be accessing multiple connections simultaneously. So depending on your current request load, you could very well have multiple threads contending for a limited amount of connections. + + +Custom configuration +-------------------- + +You can configure your own code through the Rails configuration object with custom configuration. It works like this: + + ```ruby + config.x.payment_processing.schedule = :daily + config.x.payment_processing.retries = 3 + config.x.super_debugger = true + ``` + +These configuration points are then available through the configuration object: + + ```ruby + Rails.configuration.x.payment_processing.schedule # => :daily + Rails.configuration.x.payment_processing.retries # => 3 + Rails.configuration.x.super_debugger # => true + Rails.configuration.x.super_debugger.not_set # => nil + ``` -- cgit v1.2.3 From edfc7b96a12fa4422071b61f55da5a7a238b78b2 Mon Sep 17 00:00:00 2001 From: Johnny Shields Date: Sun, 3 Aug 2014 06:51:58 +0900 Subject: [ci skip] Guides: Add definition of `config.assets.manifest` option to configuring.md --- guides/source/configuring.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 6e897d1714..c74ed03170 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -151,6 +151,8 @@ pipeline is enabled. It is set to true by default. * `config.assets.prefix` defines the prefix where assets are served from. Defaults to `/assets`. +* `config.assets.manifest` defines the full path to be used for the asset precompiler's manifest file. Defaults to a file named `manifest-.json` in the `config.assets.prefix` directory within the public folder. + * `config.assets.digest` enables the use of MD5 fingerprints in asset names. Set to `true` by default in `production.rb`. * `config.assets.debug` disables the concatenation and compression of assets. Set to `true` by default in `development.rb`. -- cgit v1.2.3 From c294e91d00696e910e05ad1428ba3ce4884bc6a3 Mon Sep 17 00:00:00 2001 From: Stefan Kanev Date: Tue, 5 Aug 2014 19:38:20 +0300 Subject: Add after_bundle to the release notes and upgrade guide --- guides/source/4_2_release_notes.md | 3 +++ guides/source/upgrading_ruby_on_rails.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'guides/source') diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md index 12db528b91..a39dd9ace0 100644 --- a/guides/source/4_2_release_notes.md +++ b/guides/source/4_2_release_notes.md @@ -85,6 +85,9 @@ Please refer to the [Changelog][railties] for detailed changes. * Introduced `Rails.gem_version` as a convenience method to return `Gem::Version.new(Rails.version)`. ([Pull Request](https://github.com/rails/rails/pull/14101)) +* Introduced an `after_bundle` callback in the Rails templates. + ([Pull Request](https://github.com/rails/rails/pull/16359)) + Action Pack ----------- diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index b3e4505fc0..62e4071935 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -58,6 +58,38 @@ When assigning `nil` to a serialized attribute, it will be saved to the database as `NULL` instead of passing the `nil` value through the coder (e.g. `"null"` when using the `JSON` coder). +### `after_bundle` in Rails templates + +If you have a Rails template that adds all the files in version control, it +fails to add the generated binstubs because it gets executed before Bundler: + +```ruby +# template.rb +generate(:scaffold, "person name:string") +route "root to: 'people#index'" +rake("db:migrate") + +git :init +git add: "." +git commit: %Q{ -m 'Initial commit' } +``` + +You can now wrap the `git` calls in an `after_bundle` block. It will be run +after the binstubs have been generated. + +```ruby +# template.rb +generate(:scaffold, "person name:string") +route "root to: 'people#index'" +rake("db:migrate") + +after_bundle do + git :init + git add: "." + git commit: %Q{ -m 'Initial commit' } +end +``` + Upgrading from Rails 4.0 to Rails 4.1 ------------------------------------- -- cgit v1.2.3 From b20d11133d18dad09f2778c9ac0c3ee362221e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20=C3=81lvarez=20Fern=C3=A1ndez?= Date: Fri, 8 Aug 2014 15:13:40 +0200 Subject: Fix typo in plugins doc --- guides/source/plugins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/plugins.md b/guides/source/plugins.md index a35648d341..489bd227cd 100644 --- a/guides/source/plugins.md +++ b/guides/source/plugins.md @@ -45,7 +45,7 @@ $ bin/rails plugin new yaffle See usage and options by asking for help: ```bash -$ bin/rails plugin --help +$ bin/rails plugin new --help ``` Testing Your Newly Generated Plugin -- cgit v1.2.3 From 38e8bb830108f91a8de832631c5147e1beea08b6 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 10 Aug 2014 22:10:15 +0900 Subject: [ci skip] Fix sample code in engines guide --- guides/source/engines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/engines.md b/guides/source/engines.md index e9cce3f159..24548a5b01 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -136,7 +136,7 @@ following to the dummy application's routes file at `test/dummy/config/routes.rb`: ```ruby -mount Blorgh::Engine, at: "blorgh" +mount Blorgh::Engine => "/blorgh" ``` ### Inside an Engine @@ -173,7 +173,7 @@ Within `lib/blorgh/engine.rb` is the base class for the engine: ```ruby module Blorgh - class Engine < Rails::Engine + class Engine < ::Rails::Engine isolate_namespace Blorgh end end -- cgit v1.2.3 From d71433d7d4423b26d51dba881e9ba8199a471c3b Mon Sep 17 00:00:00 2001 From: Robert Eshleman Date: Sun, 10 Aug 2014 19:45:42 -0400 Subject: Cleanup Guides Guidelines [ci skip] * Copy editing for clarity in several locations * Rename "Titles" section to "Headings" * Fix incorrect anchor in link to API Documentation Guidelines for filenames --- guides/source/ruby_on_rails_guides_guidelines.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'guides/source') diff --git a/guides/source/ruby_on_rails_guides_guidelines.md b/guides/source/ruby_on_rails_guides_guidelines.md index f0230b428b..6206b3c715 100644 --- a/guides/source/ruby_on_rails_guides_guidelines.md +++ b/guides/source/ruby_on_rails_guides_guidelines.md @@ -13,17 +13,17 @@ After reading this guide, you will know: Markdown ------- -Guides are written in [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown). There is comprehensive [documentation for Markdown](http://daringfireball.net/projects/markdown/syntax), a [cheatsheet](http://daringfireball.net/projects/markdown/basics). +Guides are written in [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown). There is comprehensive [documentation for Markdown](http://daringfireball.net/projects/markdown/syntax), as well as a [cheatsheet](http://daringfireball.net/projects/markdown/basics). Prologue -------- -Each guide should start with motivational text at the top (that's the little introduction in the blue area). The prologue should tell the reader what the guide is about, and what they will learn. See for example the [Routing Guide](routing.html). +Each guide should start with motivational text at the top (that's the little introduction in the blue area). The prologue should tell the reader what the guide is about, and what they will learn. As an example, see the [Routing Guide](routing.html). -Titles +Headings ------ -The title of every guide uses `h1`; guide sections use `h2`; subsections `h3`; etc. However, the generated HTML output will have the heading tag starting from `

`. +The title of every guide uses an `h1` heading; guide sections use `h2` headings; subsections use `h3` headings; etc. Note that the generated HTML output will use heading tags starting with `

`. ``` Guide Title @@ -35,14 +35,14 @@ Section ### Sub Section ``` -Capitalize all words except for internal articles, prepositions, conjunctions, and forms of the verb to be: +When writing headings, capitalize all words except for prepositions, conjunctions, internal articles, and forms of the verb "to be": ``` #### Middleware Stack is an Array #### When are Objects Saved? ``` -Use the same typography as in regular text: +Use the same inline formatting as regular text: ``` ##### The `:content_type` Option @@ -51,25 +51,23 @@ Use the same typography as in regular text: API Documentation Guidelines ---------------------------- -The guides and the API should be coherent and consistent where appropriate. Please have a look at these particular sections of the [API Documentation Guidelines](api_documentation_guidelines.html): +The guides and the API should be coherent and consistent where appropriate. In particular, these sections of the [API Documentation Guidelines](api_documentation_guidelines.html) also apply to the guides: * [Wording](api_documentation_guidelines.html#wording) * [Example Code](api_documentation_guidelines.html#example-code) -* [Filenames](api_documentation_guidelines.html#filenames) +* [Filenames](api_documentation_guidelines.html#file-names) * [Fonts](api_documentation_guidelines.html#fonts) -Those guidelines apply also to guides. - HTML Guides ----------- Before generating the guides, make sure that you have the latest version of Bundler installed on your system. As of this writing, you must install Bundler 1.3.5 on your device. -To install the latest version of Bundler, simply run the `gem install bundler` command +To install the latest version of Bundler, run `gem install bundler`. ### Generation -To generate all the guides, just `cd` into the `guides` directory, run `bundle install` and execute: +To generate all the guides, just `cd` into the `guides` directory, run `bundle install`, and execute: ``` bundle exec rake guides:generate -- cgit v1.2.3 From 784f2c5b317d86ac9e19c9e8b6bbf9efe4384be0 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 12 Aug 2014 18:07:07 +0900 Subject: [ci skip] Fix broken url in plugins guide --- guides/source/plugins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/plugins.md b/guides/source/plugins.md index 489bd227cd..f10699fbeb 100644 --- a/guides/source/plugins.md +++ b/guides/source/plugins.md @@ -440,5 +440,5 @@ $ bin/rake rdoc * [Developing a RubyGem using Bundler](https://github.com/radar/guides/blob/master/gem-development.md) * [Using .gemspecs as Intended](http://yehudakatz.com/2010/04/02/using-gemspecs-as-intended/) -* [Gemspec Reference](http://docs.rubygems.org/read/chapter/20) +* [Gemspec Reference](http://guides.rubygems.org/specification-reference/) * [GemPlugins: A Brief Introduction to the Future of Rails Plugins](http://www.intridea.com/blog/2008/6/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins) -- cgit v1.2.3