Skip to content
This repository
Browse code

Switch to 1.9 hash syntax

  • Loading branch information...
commit 6f54aac0489ac9be2e86c057ef5353f5c87620d9 1 parent fe30769
Agis Anastasopoulos authored November 16, 2012

Showing 1 changed file with 22 additions and 22 deletions. Show diff stats Hide diff stats

  1. 44  guides/source/migrations.md
44  guides/source/migrations.md
Source Rendered
@@ -64,9 +64,9 @@ bad data in the database or populate new fields:
64 64
 class AddReceiveNewsletterToUsers < ActiveRecord::Migration
65 65
   def up
66 66
     change_table :users do |t|
67  
-      t.boolean :receive_newsletter, :default => false
  67
+      t.boolean :receive_newsletter, default: false
68 68
     end
69  
-    User.update_all :receive_newsletter => true
  69
+    User.update_all receive_newsletter: true
70 70
   end
71 71
 
72 72
   def down
@@ -215,7 +215,7 @@ columns of types not supported by Active Record when using the non-sexy syntax s
215 215
 
216 216
 ```ruby
217 217
 create_table :products do |t|
218  
-  t.column :name, 'polygon', :null => false
  218
+  t.column :name, 'polygon', null: false
219 219
 end
220 220
 ```
221 221
 
@@ -349,7 +349,7 @@ generates
349 349
 ```ruby
350 350
 class AddUserRefToProducts < ActiveRecord::Migration
351 351
   def change
352  
-    add_reference :products, :user, :index => true
  352
+    add_reference :products, :user, index: true
353 353
   end
354 354
 end
355 355
 ```
@@ -377,8 +377,8 @@ will produce a migration that looks like this
377 377
 ```ruby
378 378
 class AddDetailsToProducts < ActiveRecord::Migration
379 379
   def change
380  
-    add_column :products, :price, :precision => 5, :scale => 2
381  
-    add_reference :products, :user, :polymorphic => true, :index => true
  380
+    add_column :products, :price, precision: 5, scale: 2
  381
+    add_reference :products, :user, polymorphic: true, index: true
382 382
   end
383 383
 end
384 384
 ```
@@ -408,7 +408,7 @@ are two ways of doing it. The first (traditional) form looks like
408 408
 
409 409
 ```ruby
410 410
 create_table :products do |t|
411  
-  t.column :name, :string, :null => false
  411
+  t.column :name, :string, null: false
412 412
 end
413 413
 ```
414 414
 
@@ -418,20 +418,20 @@ of that type. Subsequent parameters are the same.
418 418
 
419 419
 ```ruby
420 420
 create_table :products do |t|
421  
-  t.string :name, :null => false
  421
+  t.string :name, null: false
422 422
 end
423 423
 ```
424 424
 
425 425
 By default, `create_table` will create a primary key called `id`. You can change
426 426
 the name of the primary key with the `:primary_key` option (don't forget to
427 427
 update the corresponding model) or, if you don't want a primary key at all (for
428  
-example for a HABTM join table), you can pass the option `:id => false`. If you
  428
+example for a HABTM join table), you can pass the option `id: false`. If you
429 429
 need to pass database specific options you can place an SQL fragment in the
430 430
 `:options` option. For example,
431 431
 
432 432
 ```ruby
433  
-create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
434  
-  t.string :name, :null => false
  433
+create_table :products, options: "ENGINE=BLACKHOLE" do |t|
  434
+  t.string :name, null: false
435 435
 end
436 436
 ```
437 437
 
@@ -453,7 +453,7 @@ These columns have the option `:null` set to `false` by default.
453 453
 You can pass the option `:table_name` with you want to customize the table name. For example,
454 454
 
455 455
 ```ruby
456  
-create_join_table :products, :categories, :table_name => :categorization
  456
+create_join_table :products, :categories, table_name: :categorization
457 457
 ```
458 458
 
459 459
 will create a `categorization` table.
@@ -462,7 +462,7 @@ By default, `create_join_table` will create two columns with no options, but you
462 462
 options using the `:column_options` option. For example,
463 463
 
464 464
 ```ruby
465  
-create_join_table :products, :categories, :column_options => {:null => true}
  465
+create_join_table :products, :categories, column_options: {null: true}
466 466
 ```
467 467
 
468 468
 will create the `product_id` and `category_id` with the `:null` option as `true`.
@@ -523,7 +523,7 @@ of the columns required:
523 523
 
524 524
 ```ruby
525 525
 create_table :products do |t|
526  
-  t.references :attachment, :polymorphic => {:default => 'Photo'}
  526
+  t.references :attachment, polymorphic: {default: 'Photo'}
527 527
 end
528 528
 ```
529 529
 
@@ -533,7 +533,7 @@ index directly, instead of using `add_index` after the `create_table` call:
533 533
 
534 534
 ```ruby
535 535
 create_table :products do |t|
536  
-  t.references :category, :index => true
  536
+  t.references :category, index: true
537 537
 end
538 538
 ```
539 539
 
@@ -795,7 +795,7 @@ column.
795 795
 class AddFlagToProduct < ActiveRecord::Migration
796 796
   def change
797 797
     add_column :products, :flag, :boolean
798  
-    Product.update_all :flag => false
  798
+    Product.update_all flag: false
799 799
   end
800 800
 end
801 801
 ```
@@ -804,7 +804,7 @@ end
804 804
 # app/model/product.rb
805 805
 
806 806
 class Product < ActiveRecord::Base
807  
-  validates :flag, :presence => true
  807
+  validates :flag, presence: true
808 808
 end
809 809
 ```
810 810
 
@@ -818,7 +818,7 @@ column.
818 818
 class AddFuzzToProduct < ActiveRecord::Migration
819 819
   def change
820 820
     add_column :products, :fuzz, :string
821  
-    Product.update_all :fuzz => 'fuzzy'
  821
+    Product.update_all fuzz: 'fuzzy'
822 822
   end
823 823
 end
824 824
 ```
@@ -827,7 +827,7 @@ end
827 827
 # app/model/product.rb
828 828
 
829 829
 class Product < ActiveRecord::Base
830  
-  validates :flag, :fuzz, :presence => true
  830
+  validates :flag, :fuzz, presence: true
831 831
 end
832 832
 ```
833 833
 
@@ -870,7 +870,7 @@ class AddFlagToProduct < ActiveRecord::Migration
870 870
   def change
871 871
     add_column :products, :flag, :boolean
872 872
     Product.reset_column_information
873  
-    Product.update_all :flag => false
  873
+    Product.update_all flag: false
874 874
   end
875 875
 end
876 876
 ```
@@ -885,7 +885,7 @@ class AddFuzzToProduct < ActiveRecord::Migration
885 885
   def change
886 886
     add_column :products, :fuzz, :string
887 887
     Product.reset_column_information
888  
-    Product.update_all :fuzz => 'fuzzy'
  888
+    Product.update_all fuzz: 'fuzzy'
889 889
   end
890 890
 end
891 891
 ```
@@ -1000,7 +1000,7 @@ the database. As such, features such as triggers or foreign key constraints,
1000 1000
 which push some of that intelligence back into the database, are not heavily
1001 1001
 used.
1002 1002
 
1003  
-Validations such as `validates :foreign_key, :uniqueness => true` are one way in
  1003
+Validations such as `validates :foreign_key, uniqueness: true` are one way in
1004 1004
 which models can enforce data integrity. The `:dependent` option on associations
1005 1005
 allows models to automatically destroy child objects when the parent is
1006 1006
 destroyed. Like anything which operates at the application level, these cannot

0 notes on commit 6f54aac

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