From 2fb1cdd0a5cfdac73d8152fd33bc8c1821ea9717 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 6 Mar 2013 03:56:36 +0900 Subject: Typppo --- activerecord/lib/active_record/associations.rb | 2 +- guides/source/active_support_instrumentation.md | 2 +- guides/source/association_basics.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 35e4eb19a4..5b6f885122 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1231,7 +1231,7 @@ module ActiveRecord # its owner is destroyed: # # * :destroy causes the associated object to also be destroyed - # * :delete causes the asssociated object to be deleted directly from the database (so callbacks will not execute) + # * :delete causes the associated object to be deleted directly from the database (so callbacks will not execute) # * :nullify causes the foreign key to be set to +NULL+. Callbacks are not executed. # * :restrict_with_exception causes an exception to be raised if there is an associated record # * :restrict_with_error causes an error to be added to the owner if there is an associated object diff --git a/guides/source/active_support_instrumentation.md b/guides/source/active_support_instrumentation.md index 6b3be69942..d08000eb69 100644 --- a/guides/source/active_support_instrumentation.md +++ b/guides/source/active_support_instrumentation.md @@ -450,7 +450,7 @@ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*a data # { extra: :information } ``` -You may also subscribe to events matching a regular expresssion. This enables you to subscribe to +You may also subscribe to events matching a regular expression. This enables you to subscribe to multiple events at once. Here's you could subscribe to everything from `ActionController`. ```ruby diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index cb0a7c8026..65c8154064 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -1109,7 +1109,7 @@ end Controls what happens to the associated object when its owner is destroyed: * `:destroy` causes the associated object to also be destroyed -* `:delete` causes the asssociated object to be deleted directly from the database (so callbacks will not execute) +* `:delete` causes the associated object to be deleted directly from the database (so callbacks will not execute) * `:nullify` causes the foreign key to be set to `NULL`. Callbacks are not executed. * `:restrict_with_exception` causes an exception to be raised if there is an associated record * `:restrict_with_error` causes an error to be added to the owner if there is an associated object @@ -1463,7 +1463,7 @@ end Controls what happens to the associated objects when their owner is destroyed: * `:destroy` causes all the associated objects to also be destroyed -* `:delete_all` causes all the asssociated objects to be deleted directly from the database (so callbacks will not execute) +* `:delete_all` causes all the associated objects to be deleted directly from the database (so callbacks will not execute) * `:nullify` causes the foreign keys to be set to `NULL`. Callbacks are not executed. * `:restrict_with_exception` causes an exception to be raised if there are any associated records * `:restrict_with_error` causes an error to be added to the owner if there are any associated objects -- cgit v1.2.3 From c5b5c68d522b4bdcb5fce03a5966ec93bdd87e95 Mon Sep 17 00:00:00 2001 From: Jess Brown Date: Wed, 6 Mar 2013 14:52:23 -0500 Subject: Update capture_helper.rb if there's content for the right column, then we need the two-column class, if not the one-column --- actionpack/lib/action_view/helpers/capture_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 1bad82159a..5afe435459 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -180,7 +180,7 @@ module ActionView # My Website # <%= yield :script %> # - # + # # <%= yield %> # <%= yield :right_col %> # -- cgit v1.2.3 From b045b5c1636b61cb38d87ac761289fe0794b0f20 Mon Sep 17 00:00:00 2001 From: awilliams Date: Thu, 7 Mar 2013 19:05:27 +0100 Subject: fixes active_record_querying #pluck example --- guides/source/active_record_querying.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 0d0813c56a..575666aafb 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1399,7 +1399,7 @@ Client.select(:id).map { |c| c.id } # or Client.select(:id).map(&:id) # or -Client.select(:id).map { |c| [c.id, c.name] } +Client.select(:id, :name).map { |c| [c.id, c.name] } ``` with -- cgit v1.2.3 From 9b27e13c05a1896bfe0fbd65c496de33251cad35 Mon Sep 17 00:00:00 2001 From: Alex Robbin Date: Thu, 7 Mar 2013 23:24:27 -0500 Subject: remove the new metadata note in Rails 4 upgrade guide this was pulled out of Rails 4, see rails/rails#8399 for the discussion --- guides/source/4_0_release_notes.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/guides/source/4_0_release_notes.md b/guides/source/4_0_release_notes.md index 463da488f2..37afb25181 100644 --- a/guides/source/4_0_release_notes.md +++ b/guides/source/4_0_release_notes.md @@ -178,12 +178,6 @@ Please refer to the [Changelog](https://github.com/rails/rails/blob/master/activ If migrating down, the given migration / block is run normally. See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#reverting-previous-migrations) -* Adds some metadata columns to `schema_migrations` table. - - * `migrated_at` - * `fingerprint` - an md5 hash of the migration. - * `name` - the filename minus version and extension. - * Adds PostgreSQL array type support. Any datatype can be used to create an array column, with full migration and schema dumper support. * Add `Relation#load` to explicitly load the record and return `self`. -- cgit v1.2.3 From c27f9481dfd1d8196ff727b6f4934892b567bc01 Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Fri, 1 Mar 2013 20:16:40 +0800 Subject: Some copy edit and formatting for upgrading guide. --- guides/source/upgrading_ruby_on_rails.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 57945a256b..cb43781f52 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -43,7 +43,7 @@ Rails 4.0 no longer supports loading plugins from `vendor/plugins`. You must rep * Rails 4.0 has changed how orders get stacked in `ActiveRecord::Relation`. In previous versions of Rails, the new order was applied after the previously defined order. But this is no longer true. Check [Active Record Query guide](active_record_querying.html#ordering) for more information. -* Rails 4.0 has changed `serialized_attributes` and `attr_readonly` to class methods only. Now you shouldn't use instance methods, it's deprecated. You must change them, e.g. `self.serialized_attributes` to `self.class.serialized_attributes`. +* 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`. * 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) to a smoothly upgrade path. @@ -65,7 +65,7 @@ Rails 4.0 extracted Active Resource to its own gem. If you still need the featur ### Active Model -* Rails 4.0 has changed how errors attach with the `ActiveModel::Validations::ConfirmationValidator`. Now when confirmation validations fail the error will be attached to `:#{attribute}_confirmation` instead of `attribute`. +* Rails 4.0 has changed how errors attach with the `ActiveModel::Validations::ConfirmationValidator`. Now when confirmation validations fail, the error will be attached to `:#{attribute}_confirmation` instead of `attribute`. * Rails 4.0 has changed `ActiveModel::Serializers::JSON.include_root_in_json` default value to `false`. Now, Active Model Serializers and Active Record objects have the same default behaviour. This means that you can comment or remove the following option in the `config/initializers/wrap_parameters.rb` file: @@ -128,7 +128,7 @@ get 'こんにちは', controller: 'welcome', action: 'index' get "/" => "root#index" ``` -* Rails 4.0 has removed ActionDispatch::BestStandardsSupport middleware, !DOCTYPE html already triggers standards mode per http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx and ChromeFrame header has been moved to `config.action_dispatch.default_headers` +* Rails 4.0 has removed `ActionDispatch::BestStandardsSupport` middleware, `` already triggers standards mode per http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx and ChromeFrame header has been moved to `config.action_dispatch.default_headers`. Remember you must also remove any references to the middleware from your application code, for example: -- cgit v1.2.3 From 2b8a05f35fbf510907cd133616f45cae120e235f Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 8 Mar 2013 08:38:43 -0500 Subject: Explained how merging of scope works --- guides/source/active_record_querying.md | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 575666aafb..da1b4fcbf9 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1196,6 +1196,62 @@ Using a class method is the preferred way to accept arguments for scopes. These category.posts.created_before(time) ``` +### Merging of scopes + +Just like `where` clauses scopes are merged using `AND` conditions. + +```ruby +class User < ActiveRecord::Base + scope :active, -> { where state: 'active' } + scope :inactive, -> { where state: 'active' } +end + +```ruby +User.active.inactive +# => SELECT "users".* FROM "users" WHERE "users"."state" = 'active' AND "users"."state" = 'inactive' +``` + +We can mix and match `scope` and `where` conditions and the final sql +will have all conditions joined with `AND` . + +```ruby +User.active.where(state: 'finished') +# => SELECT "users".* FROM "users" WHERE "users"."state" = 'active' AND +"users"."state" = 'finished' +``` + +If we do want the `last where clause` to win then `Relation#merge` can +be used . + +```ruby +User.active.merge(User.inactive) +# => SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive' +``` + +One important caveat is that `default_scope` will be overridden by +`scope` and `where` conditions. + +```ruby +class User < ActiveRecord::Base + default_scope { where state: 'pending' } + scope :active, -> { where state: 'active' } + scope :inactive, -> { where state: 'active' } +end + +User.all +# => SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' + +User.active +# => SELECT "users".* FROM "users" WHERE "users"."state" = 'active' + +User.where(state: 'inactive') +# => SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive' +``` + +As you can see above the `default_scope` is being overridden by both +`scope` and `where` condition. + + ### Applying a default scope If we wish for a scope to be applied across all queries to the model we can use the -- cgit v1.2.3 From 4314d2bbb20013eefef1e52b2f57316f42c3b734 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 8 Mar 2013 08:47:38 -0500 Subject: fixing typo in the merging scopes section --- guides/source/active_record_querying.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index da1b4fcbf9..f8823fd43a 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1203,7 +1203,7 @@ Just like `where` clauses scopes are merged using `AND` conditions. ```ruby class User < ActiveRecord::Base scope :active, -> { where state: 'active' } - scope :inactive, -> { where state: 'active' } + scope :inactive, -> { where state: 'inactive' } end ```ruby @@ -1216,8 +1216,7 @@ will have all conditions joined with `AND` . ```ruby User.active.where(state: 'finished') -# => SELECT "users".* FROM "users" WHERE "users"."state" = 'active' AND -"users"."state" = 'finished' +# => SELECT "users".* FROM "users" WHERE "users"."state" = 'active' AND "users"."state" = 'finished' ``` If we do want the `last where clause` to win then `Relation#merge` can @@ -1235,7 +1234,7 @@ One important caveat is that `default_scope` will be overridden by class User < ActiveRecord::Base default_scope { where state: 'pending' } scope :active, -> { where state: 'active' } - scope :inactive, -> { where state: 'active' } + scope :inactive, -> { where state: 'inactive' } end User.all -- cgit v1.2.3 From 1fe5d36e11275a658d4503eda183dcb31b78380a Mon Sep 17 00:00:00 2001 From: Fabrizio Regini Date: Fri, 8 Mar 2013 23:29:58 +0100 Subject: Adding a note for :body option in `mail` method. --- guides/source/action_mailer_basics.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index 8720aae169..772b143f8c 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -412,6 +412,19 @@ class UserMailer < ActionMailer::Base end ``` +### Sending Emails without Template Rendering + +There may be cases in which you want to skip the template rendering step and supply the email body as a string. You can achive this using the `:body` option. +In such cases don't forget to add the `:content_type` option. Rails will default to `text/plain` otherwise. + +```ruby +class UserMailer < ActionMailer::Base + def welcome_email(user,email_body) + mail(to: user.email, body: email_body, content_type: "text/html", subject: "Already rendered!") + end +end +``` + Receiving Emails ---------------- -- cgit v1.2.3 From 1d8b56647859fc0c66149642d83b29e3118d2cb0 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Sat, 9 Mar 2013 12:17:32 +0100 Subject: strong parameter example for hashes with integer keys. This replicates the situation described in https://github.com/rails/strong_parameters/issues/114 --- guides/source/action_controller_overview.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 5861fc3d54..6b55af53cd 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -290,6 +290,20 @@ parameters: params.require(:author).permit(:name, books_attributes: [:title, :id, :_destroy]) ``` +Hasesh with integer keys are treated differently and you can declare +the attributes as if they were direct children. You get this kind of +parameters when you use `accepts_nested_attributes_for` in combination +with a `has_many` association: + +```ruby +# To whitelist the following data: +# {"book" => {"title" => "Some Book", +# "chapters_attributes" => { "1" => {"title" => "First Chapter"}, +# "2" => {"title" => "Second Chapter"}}}} + +params.require(:book).permit(:title, chapters_attributes: [:title]) +``` + #### Outside the Scope of Strong Parameters The strong parameter API was designed with the most common use cases -- cgit v1.2.3 From 41b9e86f9eaaaece9b4415c6e7da79dbec44e919 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Sat, 9 Mar 2013 12:21:28 +0100 Subject: fixed typo in strong parameters example --- guides/source/action_controller_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 6b55af53cd..7e0a8a43d4 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -290,7 +290,7 @@ parameters: params.require(:author).permit(:name, books_attributes: [:title, :id, :_destroy]) ``` -Hasesh with integer keys are treated differently and you can declare +Hashes with integer keys are treated differently and you can declare the attributes as if they were direct children. You get this kind of parameters when you use `accepts_nested_attributes_for` in combination with a `has_many` association: -- cgit v1.2.3 From be3e402c79d5c1eac4729e2982d05161c1a9b6a2 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 10 Mar 2013 00:06:51 +0530 Subject: copy edits [ci skip] --- guides/source/action_mailer_basics.md | 6 +++--- guides/source/active_record_querying.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index 772b143f8c..31182e9aed 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -403,7 +403,7 @@ If you wish to override the default delivery options (e.g. SMTP credentials) whi ```ruby class UserMailer < ActionMailer::Base - def welcome_email(user,company) + def welcome_email(user, company) @user = user @url = user_url(@user) delivery_options = { user_name: company.smtp_user, password: company.smtp_password, address: company.smtp_host } @@ -414,12 +414,12 @@ end ### Sending Emails without Template Rendering -There may be cases in which you want to skip the template rendering step and supply the email body as a string. You can achive this using the `:body` option. +There may be cases in which you want to skip the template rendering step and supply the email body as a string. You can achieve this using the `:body` option. In such cases don't forget to add the `:content_type` option. Rails will default to `text/plain` otherwise. ```ruby class UserMailer < ActionMailer::Base - def welcome_email(user,email_body) + def welcome_email(user, email_body) mail(to: user.email, body: email_body, content_type: "text/html", subject: "Already rendered!") end end diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index f8823fd43a..4a4f814917 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1248,7 +1248,7 @@ User.where(state: 'inactive') ``` As you can see above the `default_scope` is being overridden by both -`scope` and `where` condition. +`scope` and `where` conditions. ### Applying a default scope -- cgit v1.2.3