Skip to content

Commit 7b86159

Browse files
committed
Regular maintenance.
1 parent 58bb07c commit 7b86159

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

source/active_record_basics.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ models and validate that an attribute value is not empty, is unique and not
310310
already in the database, follows a specific format and many more.
311311

312312
Validation is a very important issue to consider when persisting to the database, so
313-
the methods `create`, `save` and `update` take it into account when
313+
the methods `save` and `update` take it into account when
314314
running: they return `false` when validation fails and they didn't actually
315315
perform any operation on the database. All of these have a bang counterpart (that
316-
is, `create!`, `save!` and `update!`), which are stricter in that
316+
is, `save!` and `update!`), which are stricter in that
317317
they raise the exception `ActiveRecord::RecordInvalid` if validation fails.
318318
A quick example to illustrate:
319319

@@ -322,8 +322,9 @@ class User < ActiveRecord::Base
322322
validates :name, presence: true
323323
end
324324

325-
User.create # => false
326-
User.create! # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
325+
user = User.new
326+
user.save # => false
327+
user.save! # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
327328
```
328329

329330
You can learn more about validations in the [Active Record Validations

source/asset_pipeline.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,7 @@ The directives that work in JavaScript files also work in stylesheets
493493
one, requiring all stylesheets from the current directory.
494494

495495
In this example, `require_self` is used. This puts the CSS contained within the
496-
file (if any) at the precise location of the `require_self` call. If
497-
`require_self` is called more than once, only the last call is respected.
496+
file (if any) at the precise location of the `require_self` call.
498497

499498
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)
500499
instead of these Sprockets directives. When using Sprockets directives, Sass files exist within

source/association_basics.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class CreateOrders < ActiveRecord::Migration
105105
end
106106

107107
create_table :orders do |t|
108-
t.belongs_to :customer
108+
t.belongs_to :customer, index: true
109109
t.datetime :order_date
110110
t.timestamps
111111
end
@@ -136,7 +136,7 @@ class CreateSuppliers < ActiveRecord::Migration
136136
end
137137

138138
create_table :accounts do |t|
139-
t.belongs_to :supplier
139+
t.belongs_to :supplier, index: true
140140
t.string :account_number
141141
t.timestamps
142142
end
@@ -169,7 +169,7 @@ class CreateCustomers < ActiveRecord::Migration
169169
end
170170

171171
create_table :orders do |t|
172-
t.belongs_to :customer
172+
t.belongs_to :customer, index:true
173173
t.datetime :order_date
174174
t.timestamps
175175
end
@@ -216,8 +216,8 @@ class CreateAppointments < ActiveRecord::Migration
216216
end
217217

218218
create_table :appointments do |t|
219-
t.belongs_to :physician
220-
t.belongs_to :patient
219+
t.belongs_to :physician, index: true
220+
t.belongs_to :patient, index: true
221221
t.datetime :appointment_date
222222
t.timestamps
223223
end
@@ -295,13 +295,13 @@ class CreateAccountHistories < ActiveRecord::Migration
295295
end
296296

297297
create_table :accounts do |t|
298-
t.belongs_to :supplier
298+
t.belongs_to :supplier, index: true
299299
t.string :account_number
300300
t.timestamps
301301
end
302302

303303
create_table :account_histories do |t|
304-
t.belongs_to :account
304+
t.belongs_to :account, index: true
305305
t.integer :credit_rating
306306
t.timestamps
307307
end
@@ -341,8 +341,8 @@ class CreateAssembliesAndParts < ActiveRecord::Migration
341341
end
342342

343343
create_table :assemblies_parts, id: false do |t|
344-
t.belongs_to :assembly
345-
t.belongs_to :part
344+
t.belongs_to :assembly, index: true
345+
t.belongs_to :part, index: true
346346
end
347347
end
348348
end
@@ -379,6 +379,8 @@ class CreateSuppliers < ActiveRecord::Migration
379379
t.string :account_number
380380
t.timestamps
381381
end
382+
383+
add_index :accounts, :supplier_id
382384
end
383385
end
384386
```
@@ -455,6 +457,8 @@ class CreatePictures < ActiveRecord::Migration
455457
t.string :imageable_type
456458
t.timestamps
457459
end
460+
461+
add_index :pictures, :imageable_id
458462
end
459463
end
460464
```
@@ -466,7 +470,7 @@ class CreatePictures < ActiveRecord::Migration
466470
def change
467471
create_table :pictures do |t|
468472
t.string :name
469-
t.references :imageable, polymorphic: true
473+
t.references :imageable, polymorphic: true, index: true
470474
t.timestamps
471475
end
472476
end
@@ -496,7 +500,7 @@ In your migrations/schema, you will add a references column to the model itself.
496500
class CreateEmployees < ActiveRecord::Migration
497501
def change
498502
create_table :employees do |t|
499-
t.references :manager
503+
t.references :manager, index: true
500504
t.timestamps
501505
end
502506
end
@@ -561,6 +565,8 @@ class CreateOrders < ActiveRecord::Migration
561565
t.string :order_number
562566
t.integer :customer_id
563567
end
568+
569+
add_index :orders, :customer_id
564570
end
565571
end
566572
```
@@ -594,6 +600,9 @@ class CreateAssembliesPartsJoinTable < ActiveRecord::Migration
594600
t.integer :assembly_id
595601
t.integer :part_id
596602
end
603+
604+
add_index :assemblies_parts, :assembly_id
605+
add_index :assemblies_parts, :part_id
597606
end
598607
end
599608
```

source/contributing_to_ruby_on_rails.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ You can also run any single test separately:
318318
$ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb
319319
```
320320

321+
To run a single test against all adapters, use:
322+
323+
```bash
324+
$ bundle exec rake TEST=test/cases/associations/has_many_associations_test.rb
325+
```
326+
321327
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.
322328

323329
### Warnings

source/generators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $ bin/rails generate helper --help
3535
Creating Your First Generator
3636
-----------------------------
3737

38-
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`.
38+
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`.
3939

4040
The first step is to create a file at `lib/generators/initializer_generator.rb` with the following content:
4141

source/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ To verify that you have everything installed correctly, you should be able to
120120
run the following:
121121

122122
```bash
123-
$ bin/rails --version
123+
$ rails --version
124124
```
125125

126126
If it says something like "Rails 4.2.0", you are ready to continue.

source/routing.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ match 'photos', to: 'photos#show', via: :all
645645

646646
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.
647647

648+
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.
649+
648650
### Segment Constraints
649651

650652
You can use the `:constraints` option to enforce a format for a dynamic segment:
@@ -681,7 +683,7 @@ You can also constrain a route based on any method on the [Request object](actio
681683
You specify a request-based constraint the same way that you specify a segment constraint:
682684

683685
```ruby
684-
get 'photos', constraints: { subdomain: 'admin' }
686+
get 'photos', to: 'photos#index', constraints: { subdomain: 'admin' }
685687
```
686688

687689
You can also specify constraints in a block form:

0 commit comments

Comments
 (0)