Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lifo/docrails
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaydev committed Mar 9, 2013
2 parents b3a31e9 + be3e402 commit b938f08
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 16 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/capture_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def provide(name, content = nil, &block)
# <title>My Website</title>
# <%= yield :script %>
# </head>
# <body class="<%= content_for?(:right_col) ? 'one-column' : 'two-column' %>">
# <body class="<%= content_for?(:right_col) ? 'two-column' : 'one-column' %>">
# <%= yield %>
# <%= yield :right_col %>
# </body>
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ def has_many(name, scope = nil, options = {}, &extension)
# its owner is destroyed:
#
# * <tt>:destroy</tt> causes the associated object to also be destroyed
# * <tt>:delete</tt> causes the asssociated object to be deleted directly from the database (so callbacks will not execute)
# * <tt>:delete</tt> causes the associated object to be deleted directly from the database (so callbacks will not execute)
# * <tt>:nullify</tt> causes the foreign key to be set to +NULL+. Callbacks are not executed.
# * <tt>:restrict_with_exception</tt> causes an exception to be raised if there is an associated record
# * <tt>:restrict_with_error</tt> causes an error to be added to the owner if there is an associated object
Expand Down
6 changes: 0 additions & 6 deletions guides/source/4_0_release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
14 changes: 14 additions & 0 deletions guides/source/action_controller_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ parameters:
params.require(:author).permit(:name, books_attributes: [:title, :id, :_destroy])
```

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:

```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
Expand Down
15 changes: 14 additions & 1 deletion guides/source/action_mailer_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 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)
mail(to: user.email, body: email_body, content_type: "text/html", subject: "Already rendered!")
end
end
```

Receiving Emails
----------------

Expand Down
57 changes: 56 additions & 1 deletion guides/source/active_record_querying.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,61 @@ 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: 'inactive' }
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: 'inactive' }
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` conditions.


### Applying a default scope

If we wish for a scope to be applied across all queries to the model we can use the
Expand Down Expand Up @@ -1399,7 +1454,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
Expand Down
2 changes: 1 addition & 1 deletion guides/source/active_support_instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions guides/source/association_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions guides/source/upgrading_ruby_on_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:

Expand Down Expand Up @@ -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, `<!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`.

Remember you must also remove any references to the middleware from your application code, for example:

Expand Down

0 comments on commit b938f08

Please sign in to comment.