rails 4.1.1 → 4.1.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/guides/CHANGELOG.md +11 -0
- data/guides/code/getting_started/Gemfile +3 -3
- data/guides/code/getting_started/Gemfile.lock +42 -43
- data/guides/code/getting_started/test/test_helper.rb +0 -3
- data/guides/source/_welcome.html.erb +5 -2
- data/guides/source/action_mailer_basics.md +3 -3
- data/guides/source/action_view_overview.md +1 -1
- data/guides/source/active_record_querying.md +4 -2
- data/guides/source/active_record_validations.md +1 -1
- data/guides/source/active_support_core_extensions.md +1 -1
- data/guides/source/api_documentation_guidelines.md +34 -0
- data/guides/source/asset_pipeline.md +6 -6
- data/guides/source/command_line.md +31 -31
- data/guides/source/configuring.md +3 -3
- data/guides/source/debugging_rails_applications.md +2 -2
- data/guides/source/engines.md +13 -13
- data/guides/source/generators.md +12 -12
- data/guides/source/getting_started.md +15 -15
- data/guides/source/i18n.md +2 -2
- data/guides/source/maintenance_policy.md +3 -3
- data/guides/source/migrations.md +17 -16
- data/guides/source/plugins.md +7 -7
- data/guides/source/rails_application_templates.md +2 -2
- data/guides/source/rails_on_rack.md +2 -2
- data/guides/source/routing.md +1 -1
- data/guides/source/testing.md +9 -14
- data/guides/source/upgrading_ruby_on_rails.md +17 -8
- metadata +41 -61
@@ -552,7 +552,7 @@ development:
|
|
552
552
|
$ echo $DATABASE_URL
|
553
553
|
postgresql://localhost/my_database
|
554
554
|
|
555
|
-
$ rails runner 'puts ActiveRecord::Base.connections'
|
555
|
+
$ bin/rails runner 'puts ActiveRecord::Base.connections'
|
556
556
|
{"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database"}}
|
557
557
|
```
|
558
558
|
|
@@ -569,7 +569,7 @@ development:
|
|
569
569
|
$ echo $DATABASE_URL
|
570
570
|
postgresql://localhost/my_database
|
571
571
|
|
572
|
-
$ rails runner 'puts ActiveRecord::Base.connections'
|
572
|
+
$ bin/rails runner 'puts ActiveRecord::Base.connections'
|
573
573
|
{"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database", "pool"=>5}}
|
574
574
|
```
|
575
575
|
|
@@ -585,7 +585,7 @@ development:
|
|
585
585
|
$ echo $DATABASE_URL
|
586
586
|
postgresql://localhost/my_database
|
587
587
|
|
588
|
-
$ rails runner 'puts ActiveRecord::Base.connections'
|
588
|
+
$ bin/rails runner 'puts ActiveRecord::Base.connections'
|
589
589
|
{"development"=>{"adapter"=>"sqlite3", "database"=>"NOT_my_database"}}
|
590
590
|
```
|
591
591
|
|
@@ -279,7 +279,7 @@ Make sure you have started your web server with the option `--debugger`:
|
|
279
279
|
```bash
|
280
280
|
$ rails server --debugger
|
281
281
|
=> Booting WEBrick
|
282
|
-
=> Rails 4.
|
282
|
+
=> Rails 4.1.1 application starting on http://0.0.0.0:3000
|
283
283
|
=> Debugger enabled
|
284
284
|
...
|
285
285
|
```
|
@@ -535,7 +535,7 @@ TIP: You can use the debugger while using `rails console`. Just remember to `req
|
|
535
535
|
|
536
536
|
```
|
537
537
|
$ rails console
|
538
|
-
Loading development environment (Rails 4.
|
538
|
+
Loading development environment (Rails 4.1.1)
|
539
539
|
>> require "debugger"
|
540
540
|
=> []
|
541
541
|
>> author = Author.first
|
data/guides/source/engines.md
CHANGED
@@ -73,13 +73,13 @@ options as appropriate to the need. For the "blorgh" example, you will need to
|
|
73
73
|
create a "mountable" engine, running this command in a terminal:
|
74
74
|
|
75
75
|
```bash
|
76
|
-
$ rails plugin new blorgh --mountable
|
76
|
+
$ bin/rails plugin new blorgh --mountable
|
77
77
|
```
|
78
78
|
|
79
79
|
The full list of options for the plugin generator may be seen by typing:
|
80
80
|
|
81
81
|
```bash
|
82
|
-
$ rails plugin --help
|
82
|
+
$ bin/rails plugin --help
|
83
83
|
```
|
84
84
|
|
85
85
|
The `--full` option tells the generator that you want to create an engine,
|
@@ -197,7 +197,7 @@ within the `Engine` class definition. Without it, classes generated in an engine
|
|
197
197
|
**may** conflict with an application.
|
198
198
|
|
199
199
|
What this isolation of the namespace means is that a model generated by a call
|
200
|
-
to `rails g model`, such as `rails g model post`, won't be called `Post`, but
|
200
|
+
to `bin/rails g model`, such as `bin/rails g model post`, won't be called `Post`, but
|
201
201
|
instead be namespaced and called `Blorgh::Post`. In addition, the table for the
|
202
202
|
model is namespaced, becoming `blorgh_posts`, rather than simply `posts`.
|
203
203
|
Similar to the model namespacing, a controller called `PostsController` becomes
|
@@ -253,7 +253,7 @@ This means that you will be able to generate new controllers and models for this
|
|
253
253
|
engine very easily by running commands like this:
|
254
254
|
|
255
255
|
```bash
|
256
|
-
rails g model
|
256
|
+
$ bin/rails g model
|
257
257
|
```
|
258
258
|
|
259
259
|
Keep in mind, of course, that anything generated with these commands inside of
|
@@ -293,7 +293,7 @@ The first thing to generate for a blog engine is the `Post` model and related
|
|
293
293
|
controller. To quickly generate this, you can use the Rails scaffold generator.
|
294
294
|
|
295
295
|
```bash
|
296
|
-
$ rails generate scaffold post title:string text:text
|
296
|
+
$ bin/rails generate scaffold post title:string text:text
|
297
297
|
```
|
298
298
|
|
299
299
|
This command will output this information:
|
@@ -451,7 +451,7 @@ From the application root, run the model generator. Tell it to generate a
|
|
451
451
|
and `text` text column.
|
452
452
|
|
453
453
|
```bash
|
454
|
-
$ rails generate model Comment post_id:integer text:text
|
454
|
+
$ bin/rails generate model Comment post_id:integer text:text
|
455
455
|
```
|
456
456
|
|
457
457
|
This will output the following:
|
@@ -471,7 +471,7 @@ called `Blorgh::Comment`. Now run the migration to create our blorgh_comments
|
|
471
471
|
table:
|
472
472
|
|
473
473
|
```bash
|
474
|
-
$ rake db:migrate
|
474
|
+
$ bin/rake db:migrate
|
475
475
|
```
|
476
476
|
|
477
477
|
To show the comments on a post, edit `app/views/blorgh/posts/show.html.erb` and
|
@@ -545,7 +545,7 @@ The route now exists, but the controller that this route goes to does not. To
|
|
545
545
|
create it, run this command from the application root:
|
546
546
|
|
547
547
|
```bash
|
548
|
-
$ rails g controller comments
|
548
|
+
$ bin/rails g controller comments
|
549
549
|
```
|
550
550
|
|
551
551
|
This will generate the following things:
|
@@ -682,14 +682,14 @@ engine's models can query them correctly. To copy these migrations into the
|
|
682
682
|
application use this command:
|
683
683
|
|
684
684
|
```bash
|
685
|
-
$ rake blorgh:install:migrations
|
685
|
+
$ bin/rake blorgh:install:migrations
|
686
686
|
```
|
687
687
|
|
688
688
|
If you have multiple engines that need migrations copied over, use
|
689
689
|
`railties:install:migrations` instead:
|
690
690
|
|
691
691
|
```bash
|
692
|
-
$ rake railties:install:migrations
|
692
|
+
$ bin/rake railties:install:migrations
|
693
693
|
```
|
694
694
|
|
695
695
|
This command, when run for the first time, will copy over all the migrations
|
@@ -810,7 +810,7 @@ of associating the records in the `blorgh_posts` table with the records in the
|
|
810
810
|
To generate this new column, run this command within the engine:
|
811
811
|
|
812
812
|
```bash
|
813
|
-
$ rails g migration add_author_id_to_blorgh_posts author_id:integer
|
813
|
+
$ bin/rails g migration add_author_id_to_blorgh_posts author_id:integer
|
814
814
|
```
|
815
815
|
|
816
816
|
NOTE: Due to the migration's name and the column specification after it, Rails
|
@@ -822,7 +822,7 @@ This migration will need to be run on the application. To do that, it must first
|
|
822
822
|
be copied using this command:
|
823
823
|
|
824
824
|
```bash
|
825
|
-
$ rake blorgh:install:migrations
|
825
|
+
$ bin/rake blorgh:install:migrations
|
826
826
|
```
|
827
827
|
|
828
828
|
Notice that only _one_ migration was copied over here. This is because the first
|
@@ -839,7 +839,7 @@ with the same name already exists. Copied migration
|
|
839
839
|
Run the migration using:
|
840
840
|
|
841
841
|
```bash
|
842
|
-
$ rake db:migrate
|
842
|
+
$ bin/rake db:migrate
|
843
843
|
```
|
844
844
|
|
845
845
|
Now with all the pieces in place, an action will take place that will associate
|
data/guides/source/generators.md
CHANGED
@@ -23,13 +23,13 @@ When you create an application using the `rails` command, you are in fact using
|
|
23
23
|
```bash
|
24
24
|
$ rails new myapp
|
25
25
|
$ cd myapp
|
26
|
-
$ rails generate
|
26
|
+
$ bin/rails generate
|
27
27
|
```
|
28
28
|
|
29
29
|
You will get a list of all generators that comes with Rails. If you need a detailed description of the helper generator, for example, you can simply do:
|
30
30
|
|
31
31
|
```bash
|
32
|
-
$ rails generate helper --help
|
32
|
+
$ bin/rails generate helper --help
|
33
33
|
```
|
34
34
|
|
35
35
|
Creating Your First Generator
|
@@ -54,13 +54,13 @@ Our new generator is quite simple: it inherits from `Rails::Generators::Base` an
|
|
54
54
|
To invoke our new generator, we just need to do:
|
55
55
|
|
56
56
|
```bash
|
57
|
-
$ rails generate initializer
|
57
|
+
$ bin/rails generate initializer
|
58
58
|
```
|
59
59
|
|
60
60
|
Before we go on, let's see our brand new generator description:
|
61
61
|
|
62
62
|
```bash
|
63
|
-
$ rails generate initializer --help
|
63
|
+
$ bin/rails generate initializer --help
|
64
64
|
```
|
65
65
|
|
66
66
|
Rails is usually able to generate good descriptions if a generator is namespaced, as `ActiveRecord::Generators::ModelGenerator`, but not in this particular case. We can solve this problem in two ways. The first one is calling `desc` inside our generator:
|
@@ -82,7 +82,7 @@ Creating Generators with Generators
|
|
82
82
|
Generators themselves have a generator:
|
83
83
|
|
84
84
|
```bash
|
85
|
-
$ rails generate generator initializer
|
85
|
+
$ bin/rails generate generator initializer
|
86
86
|
create lib/generators/initializer
|
87
87
|
create lib/generators/initializer/initializer_generator.rb
|
88
88
|
create lib/generators/initializer/USAGE
|
@@ -102,7 +102,7 @@ First, notice that we are inheriting from `Rails::Generators::NamedBase` instead
|
|
102
102
|
We can see that by invoking the description of this new generator (don't forget to delete the old generator file):
|
103
103
|
|
104
104
|
```bash
|
105
|
-
$ rails generate initializer --help
|
105
|
+
$ bin/rails generate initializer --help
|
106
106
|
Usage:
|
107
107
|
rails generate initializer NAME [options]
|
108
108
|
```
|
@@ -130,7 +130,7 @@ end
|
|
130
130
|
And let's execute our generator:
|
131
131
|
|
132
132
|
```bash
|
133
|
-
$ rails generate initializer core_extensions
|
133
|
+
$ bin/rails generate initializer core_extensions
|
134
134
|
```
|
135
135
|
|
136
136
|
We can see that now an initializer named core_extensions was created at `config/initializers/core_extensions.rb` with the contents of our template. That means that `copy_file` copied a file in our source root to the destination path we gave. The method `file_name` is automatically created when we inherit from `Rails::Generators::NamedBase`.
|
@@ -169,7 +169,7 @@ end
|
|
169
169
|
Before we customize our workflow, let's first see what our scaffold looks like:
|
170
170
|
|
171
171
|
```bash
|
172
|
-
$ rails generate scaffold User name:string
|
172
|
+
$ bin/rails generate scaffold User name:string
|
173
173
|
invoke active_record
|
174
174
|
create db/migrate/20130924151154_create_users.rb
|
175
175
|
create app/models/user.rb
|
@@ -224,7 +224,7 @@ If we generate another resource with the scaffold generator, we can see that sty
|
|
224
224
|
To demonstrate this, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator within the rails namespace, as this is where rails searches for generators used as hooks:
|
225
225
|
|
226
226
|
```bash
|
227
|
-
$ rails generate generator rails/my_helper
|
227
|
+
$ bin/rails generate generator rails/my_helper
|
228
228
|
create lib/generators/rails/my_helper
|
229
229
|
create lib/generators/rails/my_helper/my_helper_generator.rb
|
230
230
|
create lib/generators/rails/my_helper/USAGE
|
@@ -251,7 +251,7 @@ end
|
|
251
251
|
We can try out our new generator by creating a helper for users:
|
252
252
|
|
253
253
|
```bash
|
254
|
-
$ rails generate my_helper products
|
254
|
+
$ bin/rails generate my_helper products
|
255
255
|
create app/helpers/products_helper.rb
|
256
256
|
```
|
257
257
|
|
@@ -279,7 +279,7 @@ end
|
|
279
279
|
and see it in action when invoking the generator:
|
280
280
|
|
281
281
|
```bash
|
282
|
-
$ rails generate scaffold Post body:text
|
282
|
+
$ bin/rails generate scaffold Post body:text
|
283
283
|
[...]
|
284
284
|
invoke my_helper
|
285
285
|
create app/helpers/posts_helper.rb
|
@@ -365,7 +365,7 @@ end
|
|
365
365
|
Now, if you create a Comment scaffold, you will see that the shoulda generators are being invoked, and at the end, they are just falling back to TestUnit generators:
|
366
366
|
|
367
367
|
```bash
|
368
|
-
$ rails generate scaffold Comment body:text
|
368
|
+
$ bin/rails generate scaffold Comment body:text
|
369
369
|
invoke active_record
|
370
370
|
create db/migrate/20130924143118_create_comments.rb
|
371
371
|
create app/models/comment.rb
|
@@ -91,7 +91,7 @@ current version of Ruby installed:
|
|
91
91
|
|
92
92
|
TIP. A number of tools exist to help you quickly install Ruby and Ruby
|
93
93
|
on Rails on your system. Windows users can use [Rails Installer](http://railsinstaller.org),
|
94
|
-
while Mac OS X users can use [
|
94
|
+
while Mac OS X users can use [Tokaido](https://github.com/tokaido/tokaidoapp).
|
95
95
|
|
96
96
|
```bash
|
97
97
|
$ ruby -v
|
@@ -122,10 +122,10 @@ To verify that you have everything installed correctly, you should be able to
|
|
122
122
|
run the following:
|
123
123
|
|
124
124
|
```bash
|
125
|
-
$ rails --version
|
125
|
+
$ bin/rails --version
|
126
126
|
```
|
127
127
|
|
128
|
-
If it says something like "Rails 4.1.
|
128
|
+
If it says something like "Rails 4.1.1", you are ready to continue.
|
129
129
|
|
130
130
|
### Creating the Blog Application
|
131
131
|
|
@@ -190,7 +190,7 @@ start a web server on your development machine. You can do this by running the
|
|
190
190
|
following in the `blog` directory:
|
191
191
|
|
192
192
|
```bash
|
193
|
-
$ rails server
|
193
|
+
$ bin/rails server
|
194
194
|
```
|
195
195
|
|
196
196
|
TIP: Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the
|
@@ -243,7 +243,7 @@ tell it you want a controller called "welcome" with an action called "index",
|
|
243
243
|
just like this:
|
244
244
|
|
245
245
|
```bash
|
246
|
-
$ rails generate controller welcome index
|
246
|
+
$ bin/rails generate controller welcome index
|
247
247
|
```
|
248
248
|
|
249
249
|
Rails will create several files and a route for you.
|
@@ -358,7 +358,7 @@ will be seen later, but for now notice that Rails has inferred the
|
|
358
358
|
singular form `article` and makes meaningful use of the distinction.
|
359
359
|
|
360
360
|
```bash
|
361
|
-
$ rake routes
|
361
|
+
$ bin/rake routes
|
362
362
|
Prefix Verb URI Pattern Controller#Action
|
363
363
|
articles GET /articles(.:format) articles#index
|
364
364
|
POST /articles(.:format) articles#create
|
@@ -396,7 +396,7 @@ a controller called `ArticlesController`. You can do this by running this
|
|
396
396
|
command:
|
397
397
|
|
398
398
|
```bash
|
399
|
-
$ rails g controller articles
|
399
|
+
$ bin/rails g controller articles
|
400
400
|
```
|
401
401
|
|
402
402
|
If you open up the newly generated `app/controllers/articles_controller.rb`
|
@@ -552,7 +552,7 @@ To see what Rails will do with this, we look back at the output of
|
|
552
552
|
`rake routes`:
|
553
553
|
|
554
554
|
```bash
|
555
|
-
$ rake routes
|
555
|
+
$ bin/rake routes
|
556
556
|
Prefix Verb URI Pattern Controller#Action
|
557
557
|
articles GET /articles(.:format) articles#index
|
558
558
|
POST /articles(.:format) articles#create
|
@@ -612,7 +612,7 @@ def create
|
|
612
612
|
end
|
613
613
|
```
|
614
614
|
|
615
|
-
The `render` method here is taking a very simple hash with a key of `
|
615
|
+
The `render` method here is taking a very simple hash with a key of `plain` and
|
616
616
|
value of `params[:article].inspect`. The `params` method is the object which
|
617
617
|
represents the parameters (or fields) coming in from the form. The `params`
|
618
618
|
method returns an `ActiveSupport::HashWithIndifferentAccess` object, which
|
@@ -638,7 +638,7 @@ most Rails developers tend to use when creating new models.
|
|
638
638
|
To create the new model, run this command in your terminal:
|
639
639
|
|
640
640
|
```bash
|
641
|
-
$ rails generate model Article title:string text:text
|
641
|
+
$ bin/rails generate model Article title:string text:text
|
642
642
|
```
|
643
643
|
|
644
644
|
With that command we told Rails that we want a `Article` model, together
|
@@ -696,7 +696,7 @@ Migrations](migrations.html).
|
|
696
696
|
At this point, you can use a rake command to run the migration:
|
697
697
|
|
698
698
|
```bash
|
699
|
-
$ rake db:migrate
|
699
|
+
$ bin/rake db:migrate
|
700
700
|
```
|
701
701
|
|
702
702
|
Rails will execute this migration command and tell you it created the Articles
|
@@ -1119,7 +1119,7 @@ The `method: :patch` option tells Rails that we want this form to be submitted
|
|
1119
1119
|
via the `PATCH` HTTP method which is the HTTP method you're expected to use to
|
1120
1120
|
**update** resources according to the REST protocol.
|
1121
1121
|
|
1122
|
-
The first parameter of
|
1122
|
+
The first parameter of `form_for` can be an object, say, `@article` which would
|
1123
1123
|
cause the helper to fill in the form with the fields of the object. Passing in a
|
1124
1124
|
symbol (`:article`) with the same name as the instance variable (`@article`) also
|
1125
1125
|
automagically leads to the same behavior. This is what is happening here. More details
|
@@ -1361,7 +1361,7 @@ the `Article` model. This time we'll create a `Comment` model to hold
|
|
1361
1361
|
reference of article comments. Run this command in your terminal:
|
1362
1362
|
|
1363
1363
|
```bash
|
1364
|
-
$ rails generate model Comment commenter:string body:text article:references
|
1364
|
+
$ bin/rails generate model Comment commenter:string body:text article:references
|
1365
1365
|
```
|
1366
1366
|
|
1367
1367
|
This command will generate four files:
|
@@ -1409,7 +1409,7 @@ the two models. An index for this association is also created on this column.
|
|
1409
1409
|
Go ahead and run the migration:
|
1410
1410
|
|
1411
1411
|
```bash
|
1412
|
-
$ rake db:migrate
|
1412
|
+
$ bin/rake db:migrate
|
1413
1413
|
```
|
1414
1414
|
|
1415
1415
|
Rails is smart enough to only execute the migrations that have not already been
|
@@ -1485,7 +1485,7 @@ With the model in hand, you can turn your attention to creating a matching
|
|
1485
1485
|
controller. Again, we'll use the same generator we used before:
|
1486
1486
|
|
1487
1487
|
```bash
|
1488
|
-
$ rails generate controller Comments
|
1488
|
+
$ bin/rails generate controller Comments
|
1489
1489
|
```
|
1490
1490
|
|
1491
1491
|
This creates six files and one empty directory:
|
data/guides/source/i18n.md
CHANGED
@@ -179,7 +179,7 @@ end
|
|
179
179
|
# in your /etc/hosts file to try this out locally
|
180
180
|
def extract_locale_from_tld
|
181
181
|
parsed_locale = request.host.split('.').last
|
182
|
-
I18n.available_locales.include?(parsed_locale
|
182
|
+
I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale : nil
|
183
183
|
end
|
184
184
|
```
|
185
185
|
|
@@ -192,7 +192,7 @@ We can also set the locale from the _subdomain_ in a very similar way:
|
|
192
192
|
# in your /etc/hosts file to try this out locally
|
193
193
|
def extract_locale_from_subdomain
|
194
194
|
parsed_locale = request.subdomains.first
|
195
|
-
I18n.available_locales.include?(parsed_locale
|
195
|
+
I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale : nil
|
196
196
|
end
|
197
197
|
```
|
198
198
|
|
@@ -20,7 +20,7 @@ Only the latest release series will receive bug fixes. When enough bugs are
|
|
20
20
|
fixed and its deemed worthy to release a new gem, this is the branch it happens
|
21
21
|
from.
|
22
22
|
|
23
|
-
**Currently included series:** 4.0.z
|
23
|
+
**Currently included series:** 4.1.z, 4.0.z
|
24
24
|
|
25
25
|
Security Issues
|
26
26
|
---------------
|
@@ -35,7 +35,7 @@ be built from 1.2.2, and then added to the end of 1-2-stable. This means that
|
|
35
35
|
security releases are easy to upgrade to if you're running the latest version
|
36
36
|
of Rails.
|
37
37
|
|
38
|
-
**Currently included series:** 4.
|
38
|
+
**Currently included series:** 4.1.z, 4.0.z
|
39
39
|
|
40
40
|
Severe Security Issues
|
41
41
|
----------------------
|
@@ -44,7 +44,7 @@ For severe security issues we will provide new versions as above, and also the
|
|
44
44
|
last major release series will receive patches and new versions. The
|
45
45
|
classification of the security issue is judged by the core team.
|
46
46
|
|
47
|
-
**Currently included series:** 4.0.z, 3.2.z
|
47
|
+
**Currently included series:** 4.1.z, 4.0.z, 3.2.z
|
48
48
|
|
49
49
|
Unsupported Release Series
|
50
50
|
--------------------------
|
data/guides/source/migrations.md
CHANGED
@@ -120,7 +120,7 @@ Of course, calculating timestamps is no fun, so Active Record provides a
|
|
120
120
|
generator to handle making it for you:
|
121
121
|
|
122
122
|
```bash
|
123
|
-
$ rails generate migration AddPartNumberToProducts
|
123
|
+
$ bin/rails generate migration AddPartNumberToProducts
|
124
124
|
```
|
125
125
|
|
126
126
|
This will create an empty but appropriately named migration:
|
@@ -137,7 +137,7 @@ followed by a list of column names and types then a migration containing the
|
|
137
137
|
appropriate `add_column` and `remove_column` statements will be created.
|
138
138
|
|
139
139
|
```bash
|
140
|
-
$ rails generate migration AddPartNumberToProducts part_number:string
|
140
|
+
$ bin/rails generate migration AddPartNumberToProducts part_number:string
|
141
141
|
```
|
142
142
|
|
143
143
|
will generate
|
@@ -153,7 +153,7 @@ end
|
|
153
153
|
If you'd like to add an index on the new column, you can do that as well:
|
154
154
|
|
155
155
|
```bash
|
156
|
-
$ rails generate migration AddPartNumberToProducts part_number:string:index
|
156
|
+
$ bin/rails generate migration AddPartNumberToProducts part_number:string:index
|
157
157
|
```
|
158
158
|
|
159
159
|
will generate
|
@@ -171,7 +171,7 @@ end
|
|
171
171
|
Similarly, you can generate a migration to remove a column from the command line:
|
172
172
|
|
173
173
|
```bash
|
174
|
-
$ rails generate migration RemovePartNumberFromProducts part_number:string
|
174
|
+
$ bin/rails generate migration RemovePartNumberFromProducts part_number:string
|
175
175
|
```
|
176
176
|
|
177
177
|
generates
|
@@ -187,7 +187,7 @@ end
|
|
187
187
|
You are not limited to one magically generated column. For example:
|
188
188
|
|
189
189
|
```bash
|
190
|
-
$ rails generate migration AddDetailsToProducts part_number:string price:decimal
|
190
|
+
$ bin/rails generate migration AddDetailsToProducts part_number:string price:decimal
|
191
191
|
```
|
192
192
|
|
193
193
|
generates
|
@@ -206,7 +206,7 @@ followed by a list of column names and types then a migration creating the table
|
|
206
206
|
XXX with the columns listed will be generated. For example:
|
207
207
|
|
208
208
|
```bash
|
209
|
-
$ rails generate migration CreateProducts name:string part_number:string
|
209
|
+
$ bin/rails generate migration CreateProducts name:string part_number:string
|
210
210
|
```
|
211
211
|
|
212
212
|
generates
|
@@ -230,7 +230,7 @@ Also, the generator accepts column type as `references`(also available as
|
|
230
230
|
`belongs_to`). For instance:
|
231
231
|
|
232
232
|
```bash
|
233
|
-
$ rails generate migration AddUserRefToProducts user:references
|
233
|
+
$ bin/rails generate migration AddUserRefToProducts user:references
|
234
234
|
```
|
235
235
|
|
236
236
|
generates
|
@@ -248,7 +248,7 @@ This migration will create a `user_id` column and appropriate index.
|
|
248
248
|
There is also a generator which will produce join tables if `JoinTable` is part of the name:
|
249
249
|
|
250
250
|
```bash
|
251
|
-
rails g migration CreateJoinTableCustomerProduct customer product
|
251
|
+
$ bin/rails g migration CreateJoinTableCustomerProduct customer product
|
252
252
|
```
|
253
253
|
|
254
254
|
will produce the following migration:
|
@@ -272,7 +272,7 @@ relevant table. If you tell Rails what columns you want, then statements for
|
|
272
272
|
adding these columns will also be created. For example, running:
|
273
273
|
|
274
274
|
```bash
|
275
|
-
$ rails generate model Product name:string description:text
|
275
|
+
$ bin/rails generate model Product name:string description:text
|
276
276
|
```
|
277
277
|
|
278
278
|
will create a migration that looks like this
|
@@ -306,7 +306,7 @@ braces. You can use the following modifiers:
|
|
306
306
|
For instance, running:
|
307
307
|
|
308
308
|
```bash
|
309
|
-
$ rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplier:references{polymorphic}
|
309
|
+
$ bin/rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplier:references{polymorphic}
|
310
310
|
```
|
311
311
|
|
312
312
|
will produce a migration that looks like this
|
@@ -494,6 +494,7 @@ class ExampleMigration < ActiveRecord::Migration
|
|
494
494
|
add_column :users, :home_page_url, :string
|
495
495
|
rename_column :users, :email, :email_address
|
496
496
|
end
|
497
|
+
end
|
497
498
|
```
|
498
499
|
|
499
500
|
Using `reversible` will ensure that the instructions are executed in the
|
@@ -651,7 +652,7 @@ is the numerical prefix on the migration's filename. For example, to migrate
|
|
651
652
|
to version 20080906120000 run:
|
652
653
|
|
653
654
|
```bash
|
654
|
-
$ rake db:migrate VERSION=20080906120000
|
655
|
+
$ bin/rake db:migrate VERSION=20080906120000
|
655
656
|
```
|
656
657
|
|
657
658
|
If version 20080906120000 is greater than the current version (i.e., it is
|
@@ -668,7 +669,7 @@ mistake in it and wish to correct it. Rather than tracking down the version
|
|
668
669
|
number associated with the previous migration you can run:
|
669
670
|
|
670
671
|
```bash
|
671
|
-
$ rake db:rollback
|
672
|
+
$ bin/rake db:rollback
|
672
673
|
```
|
673
674
|
|
674
675
|
This will rollback the latest migration, either by reverting the `change`
|
@@ -676,7 +677,7 @@ method or by running the `down` method. If you need to undo
|
|
676
677
|
several migrations you can provide a `STEP` parameter:
|
677
678
|
|
678
679
|
```bash
|
679
|
-
$ rake db:rollback STEP=3
|
680
|
+
$ bin/rake db:rollback STEP=3
|
680
681
|
```
|
681
682
|
|
682
683
|
will revert the last 3 migrations.
|
@@ -686,7 +687,7 @@ back up again. As with the `db:rollback` task, you can use the `STEP` parameter
|
|
686
687
|
if you need to go more than one version back, for example:
|
687
688
|
|
688
689
|
```bash
|
689
|
-
$ rake db:migrate:redo STEP=3
|
690
|
+
$ bin/rake db:migrate:redo STEP=3
|
690
691
|
```
|
691
692
|
|
692
693
|
Neither of these Rake tasks do anything you could not do with `db:migrate`. They
|
@@ -716,7 +717,7 @@ the corresponding migration will have its `change`, `up` or `down` method
|
|
716
717
|
invoked, for example:
|
717
718
|
|
718
719
|
```bash
|
719
|
-
$ rake db:migrate:up VERSION=20080906120000
|
720
|
+
$ bin/rake db:migrate:up VERSION=20080906120000
|
720
721
|
```
|
721
722
|
|
722
723
|
will run the 20080906120000 migration by running the `change` method (or the
|
@@ -732,7 +733,7 @@ To run migrations against another environment you can specify it using the
|
|
732
733
|
migrations against the `test` environment you could run:
|
733
734
|
|
734
735
|
```bash
|
735
|
-
$ rake db:migrate RAILS_ENV=test
|
736
|
+
$ bin/rake db:migrate RAILS_ENV=test
|
736
737
|
```
|
737
738
|
|
738
739
|
### Changing the Output of Running Migrations
|