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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00b64b49a61883f5a5ae28f4b0362ab937c469a1
|
4
|
+
data.tar.gz: 320a5149cd8aded358ad0b9cfd59311c6b9139db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48f982acbed6f9ea7adf6a7f05f71f75dbe23e9ae8f27380f60128070fa1124752a4cd7a2ed9c3f0a038289fbb326fe5fd98dbb571c4cf1b72a06a067ad2d9dc
|
7
|
+
data.tar.gz: 8337bbdf654a812b15ccc0554ae880f2ef4f3074393700114a31c25c45a370b40a98255c02b444c376ff59c380591942037558772d8068b715a14bb277d0c18e
|
data/guides/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## Rails 4.1.2 (May 27, 2014) ##
|
2
|
+
|
3
|
+
* Update all Rails 4.1.0 references to 4.1.1 within the guides and code.
|
4
|
+
|
5
|
+
*John Kelly Ferguson*
|
6
|
+
|
7
|
+
* Updates the maintenance policy to match the latest versions of Rails.
|
8
|
+
|
9
|
+
*Matias Korhonen*
|
10
|
+
|
11
|
+
|
1
12
|
## Rails 4.1.1 (May 6, 2014) ##
|
2
13
|
|
3
14
|
* No changes.
|
@@ -2,11 +2,11 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
|
4
4
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
5
|
-
gem 'rails', '4.1.
|
6
|
-
# Use
|
5
|
+
gem 'rails', '4.1.1'
|
6
|
+
# Use SQLite3 as the database for Active Record
|
7
7
|
gem 'sqlite3'
|
8
8
|
# Use SCSS for stylesheets
|
9
|
-
gem 'sass-rails', '~> 4.0.
|
9
|
+
gem 'sass-rails', '~> 4.0.3'
|
10
10
|
# Use Uglifier as compressor for JavaScript assets
|
11
11
|
gem 'uglifier', '>= 1.3.0'
|
12
12
|
# Use CoffeeScript for .js.coffee assets and views
|
@@ -1,34 +1,33 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionmailer (4.1.
|
5
|
-
actionpack (= 4.1.
|
6
|
-
actionview (= 4.1.
|
4
|
+
actionmailer (4.1.1)
|
5
|
+
actionpack (= 4.1.1)
|
6
|
+
actionview (= 4.1.1)
|
7
7
|
mail (~> 2.5.4)
|
8
|
-
actionpack (4.1.
|
9
|
-
actionview (= 4.1.
|
10
|
-
activesupport (= 4.1.
|
8
|
+
actionpack (4.1.1)
|
9
|
+
actionview (= 4.1.1)
|
10
|
+
activesupport (= 4.1.1)
|
11
11
|
rack (~> 1.5.2)
|
12
12
|
rack-test (~> 0.6.2)
|
13
|
-
actionview (4.1.
|
14
|
-
activesupport (= 4.1.
|
13
|
+
actionview (4.1.1)
|
14
|
+
activesupport (= 4.1.1)
|
15
15
|
builder (~> 3.1)
|
16
16
|
erubis (~> 2.7.0)
|
17
|
-
activemodel (4.1.
|
18
|
-
activesupport (= 4.1.
|
17
|
+
activemodel (4.1.1)
|
18
|
+
activesupport (= 4.1.1)
|
19
19
|
builder (~> 3.1)
|
20
|
-
activerecord (4.1.
|
21
|
-
activemodel (= 4.1.
|
22
|
-
activesupport (= 4.1.
|
20
|
+
activerecord (4.1.1)
|
21
|
+
activemodel (= 4.1.1)
|
22
|
+
activesupport (= 4.1.1)
|
23
23
|
arel (~> 5.0.0)
|
24
|
-
activesupport (4.1.
|
24
|
+
activesupport (4.1.1)
|
25
25
|
i18n (~> 0.6, >= 0.6.9)
|
26
26
|
json (~> 1.7, >= 1.7.7)
|
27
27
|
minitest (~> 5.1)
|
28
28
|
thread_safe (~> 0.1)
|
29
29
|
tzinfo (~> 1.1)
|
30
|
-
arel (5.0.
|
31
|
-
atomic (1.1.14)
|
30
|
+
arel (5.0.1.20140414130214)
|
32
31
|
builder (3.2.2)
|
33
32
|
coffee-rails (4.0.1)
|
34
33
|
coffee-script (>= 2.2.0)
|
@@ -52,52 +51,52 @@ GEM
|
|
52
51
|
mime-types (~> 1.16)
|
53
52
|
treetop (~> 1.4.8)
|
54
53
|
mime-types (1.25.1)
|
55
|
-
minitest (5.
|
56
|
-
multi_json (1.
|
57
|
-
polyglot (0.3.
|
54
|
+
minitest (5.3.4)
|
55
|
+
multi_json (1.10.1)
|
56
|
+
polyglot (0.3.4)
|
58
57
|
rack (1.5.2)
|
59
58
|
rack-test (0.6.2)
|
60
59
|
rack (>= 1.0)
|
61
|
-
rails (4.1.
|
62
|
-
actionmailer (= 4.1.
|
63
|
-
actionpack (= 4.1.
|
64
|
-
actionview (= 4.1.
|
65
|
-
activemodel (= 4.1.
|
66
|
-
activerecord (= 4.1.
|
67
|
-
activesupport (= 4.1.
|
60
|
+
rails (4.1.1)
|
61
|
+
actionmailer (= 4.1.1)
|
62
|
+
actionpack (= 4.1.1)
|
63
|
+
actionview (= 4.1.1)
|
64
|
+
activemodel (= 4.1.1)
|
65
|
+
activerecord (= 4.1.1)
|
66
|
+
activesupport (= 4.1.1)
|
68
67
|
bundler (>= 1.3.0, < 2.0)
|
69
|
-
railties (= 4.1.
|
70
|
-
sprockets-rails (~> 2.0
|
71
|
-
railties (4.1.
|
72
|
-
actionpack (= 4.1.
|
73
|
-
activesupport (= 4.1.
|
68
|
+
railties (= 4.1.1)
|
69
|
+
sprockets-rails (~> 2.0)
|
70
|
+
railties (4.1.1)
|
71
|
+
actionpack (= 4.1.1)
|
72
|
+
activesupport (= 4.1.1)
|
74
73
|
rake (>= 0.8.7)
|
75
74
|
thor (>= 0.18.1, < 2.0)
|
76
|
-
rake (10.
|
75
|
+
rake (10.3.2)
|
77
76
|
rdoc (4.1.1)
|
78
77
|
json (~> 1.4)
|
79
|
-
sass (3.2.
|
80
|
-
sass-rails (4.0.
|
78
|
+
sass (3.2.19)
|
79
|
+
sass-rails (4.0.3)
|
81
80
|
railties (>= 4.0.0, < 5.0)
|
82
|
-
sass (
|
83
|
-
sprockets
|
81
|
+
sass (~> 3.2.0)
|
82
|
+
sprockets (~> 2.8, <= 2.11.0)
|
83
|
+
sprockets-rails (~> 2.0)
|
84
84
|
sdoc (0.4.0)
|
85
85
|
json (~> 1.8)
|
86
86
|
rdoc (~> 4.0, < 5.0)
|
87
87
|
spring (1.0.0)
|
88
|
-
sprockets (2.
|
88
|
+
sprockets (2.11.0)
|
89
89
|
hike (~> 1.2)
|
90
90
|
multi_json (~> 1.0)
|
91
91
|
rack (~> 1.0)
|
92
92
|
tilt (~> 1.1, != 1.3.0)
|
93
|
-
sprockets-rails (2.
|
93
|
+
sprockets-rails (2.1.3)
|
94
94
|
actionpack (>= 3.0)
|
95
95
|
activesupport (>= 3.0)
|
96
96
|
sprockets (~> 2.8)
|
97
97
|
sqlite3 (1.3.8)
|
98
|
-
thor (0.
|
99
|
-
thread_safe (0.
|
100
|
-
atomic
|
98
|
+
thor (0.19.1)
|
99
|
+
thread_safe (0.3.3)
|
101
100
|
tilt (1.4.1)
|
102
101
|
treetop (1.4.15)
|
103
102
|
polyglot
|
@@ -117,8 +116,8 @@ DEPENDENCIES
|
|
117
116
|
coffee-rails (~> 4.0.0)
|
118
117
|
jbuilder (~> 2.0)
|
119
118
|
jquery-rails
|
120
|
-
rails (= 4.1.
|
121
|
-
sass-rails (~> 4.0.
|
119
|
+
rails (= 4.1.1)
|
120
|
+
sass-rails (~> 4.0.3)
|
122
121
|
sdoc (~> 0.4.0)
|
123
122
|
spring
|
124
123
|
sqlite3
|
@@ -6,9 +6,6 @@ class ActiveSupport::TestCase
|
|
6
6
|
ActiveRecord::Migration.check_pending!
|
7
7
|
|
8
8
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
9
|
-
#
|
10
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
11
|
-
# -- they do not yet inherit this setting
|
12
9
|
fixtures :all
|
13
10
|
|
14
11
|
# Add more helper methods to be used by all tests here...
|
@@ -10,12 +10,15 @@
|
|
10
10
|
</p>
|
11
11
|
<% else %>
|
12
12
|
<p>
|
13
|
-
These are the new guides for Rails 4.
|
13
|
+
These are the new guides for Rails 4.1 based on <a href="https://github.com/rails/rails/tree/<%= @version %>"><%= @version %></a>.
|
14
14
|
These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together.
|
15
15
|
</p>
|
16
16
|
<% end %>
|
17
17
|
<p>
|
18
|
-
The guides for Rails
|
18
|
+
The guides for Rails 4.0.x are available at <a href="http://guides.rubyonrails.org/v4.0.5/">http://guides.rubyonrails.org/v4.0.5/</a>.
|
19
|
+
</p>
|
20
|
+
<p>
|
21
|
+
The guides for Rails 3.2.x are available at <a href="http://guides.rubyonrails.org/v3.2.18/">http://guides.rubyonrails.org/v3.2.18/</a>.
|
19
22
|
</p>
|
20
23
|
<p>
|
21
24
|
The guides for Rails 2.3.x are available at <a href="http://guides.rubyonrails.org/v2.3.11/">http://guides.rubyonrails.org/v2.3.11/</a>.
|
@@ -30,7 +30,7 @@ views.
|
|
30
30
|
#### Create the Mailer
|
31
31
|
|
32
32
|
```bash
|
33
|
-
$ rails generate mailer UserMailer
|
33
|
+
$ bin/rails generate mailer UserMailer
|
34
34
|
create app/mailers/user_mailer.rb
|
35
35
|
invoke erb
|
36
36
|
create app/views/user_mailer
|
@@ -146,8 +146,8 @@ Setting this up is painfully simple.
|
|
146
146
|
First, let's create a simple `User` scaffold:
|
147
147
|
|
148
148
|
```bash
|
149
|
-
$ rails generate scaffold user name email login
|
150
|
-
$ rake db:migrate
|
149
|
+
$ bin/rails generate scaffold user name email login
|
150
|
+
$ bin/rake db:migrate
|
151
151
|
```
|
152
152
|
|
153
153
|
Now that we have a user model to play with, we will just edit the
|
@@ -28,7 +28,7 @@ For each controller there is an associated directory in the `app/views` director
|
|
28
28
|
Let's take a look at what Rails does by default when creating a new resource using the scaffold generator:
|
29
29
|
|
30
30
|
```bash
|
31
|
-
$ rails generate scaffold post
|
31
|
+
$ bin/rails generate scaffold post
|
32
32
|
[...]
|
33
33
|
invoke scaffold_controller
|
34
34
|
create app/controllers/posts_controller.rb
|
@@ -753,13 +753,15 @@ Post.find(10).comments.reorder('name')
|
|
753
753
|
The SQL that would be executed:
|
754
754
|
|
755
755
|
```sql
|
756
|
-
SELECT * FROM posts WHERE id = 10
|
756
|
+
SELECT * FROM posts WHERE id = 10
|
757
|
+
SELECT * FROM comments WHERE article_id = 10 ORDER BY name
|
757
758
|
```
|
758
759
|
|
759
760
|
In case the `reorder` clause is not used, the SQL executed would be:
|
760
761
|
|
761
762
|
```sql
|
762
|
-
SELECT * FROM posts WHERE id = 10
|
763
|
+
SELECT * FROM posts WHERE id = 10
|
764
|
+
SELECT * FROM comments WHERE article_id = 10 ORDER BY posted_at DESC
|
763
765
|
```
|
764
766
|
|
765
767
|
### `reverse_order`
|
@@ -85,7 +85,7 @@ end
|
|
85
85
|
We can see how it works by looking at some `rails console` output:
|
86
86
|
|
87
87
|
```ruby
|
88
|
-
$ rails console
|
88
|
+
$ bin/rails console
|
89
89
|
>> p = Person.new(name: "John Doe")
|
90
90
|
=> #<Person id: nil, name: "John Doe", created_at: nil, updated_at: nil>
|
91
91
|
>> p.new_record?
|
@@ -1119,7 +1119,7 @@ end
|
|
1119
1119
|
|
1120
1120
|
A model may find it useful to set `:instance_accessor` to `false` as a way to prevent mass-assignment from setting the attribute.
|
1121
1121
|
|
1122
|
-
NOTE: Defined in `active_support/core_ext/module/attribute_accessors.rb`.
|
1122
|
+
NOTE: Defined in `active_support/core_ext/module/attribute_accessors.rb`.
|
1123
1123
|
|
1124
1124
|
### Subclasses & Descendants
|
1125
1125
|
|
@@ -279,3 +279,37 @@ self.class_eval %{
|
|
279
279
|
end
|
280
280
|
}
|
281
281
|
```
|
282
|
+
|
283
|
+
Method Visibility
|
284
|
+
-----------------
|
285
|
+
|
286
|
+
When writing documentation for Rails, it's important to understand the difference between public API (or User-facing) vs. internal API.
|
287
|
+
|
288
|
+
Rails, like most libraries, uses the private keyword from Ruby for defining internal API. However, public API follows a slightly different convention. Instead of assuming all public methods are designed for user consumption, Rails uses the `:nodoc:` directive to annotate these kinds of methods as internal API.
|
289
|
+
|
290
|
+
This means that there are methods in Rails with `public` visibility that aren't meant for user consumption.
|
291
|
+
|
292
|
+
An example of this is `ActiveRecord::Core::ClassMethods#arel_table`:
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
module ActiveRecord::Core::ClassMethods
|
296
|
+
def arel_table #:nodoc:
|
297
|
+
# do some magic..
|
298
|
+
end
|
299
|
+
end
|
300
|
+
```
|
301
|
+
|
302
|
+
If you thought, "this method looks like a public class method for `ActiveRecord::Core`", you were right. But actually the Rails team doesn't want users to rely on this method. So they mark it as `:nodoc:` and it's removed from public documentation. The reasoning behind this is to allow the team to change these methods according to their internal needs across releases as they see fit. The name of this method could change, or the return value, or this entire class may disappear; there's no guarantee and so you shouldn't depend on this API in your plugin or application. Otherwise, you risk your app or gem breaking when you upgrade to a newer release of Rails.
|
303
|
+
|
304
|
+
As a contributor, it's important to think about whether this API is meant for end-user consumption. The Rails team is committed to not making any breaking changes to public API across releases without going through a full deprecation cycle, which takes an eternity. It's recommended that you `:nodoc:` any of your internal methods/classes unless they're already private (meaning visibility), in which case it's internal by default. Once the API stabilizes the visibility can change from private later, but changing public API is much harder due to backwards compatibility.
|
305
|
+
|
306
|
+
A class or module is marked with `:nodoc:` to indicate that all methods are internal API and should never be used directly.
|
307
|
+
|
308
|
+
If you come across an existing `:nodoc:` you should tread lightly. Consider asking someone from the core team or author of the code before removing it. This should almost always happen through a Pull Request process instead of the docrails project.
|
309
|
+
|
310
|
+
A `:nodoc:` should never be added simply because a method or class is missing documentation. There may be an instance where an internal public method wasn't given a `:nodoc:` by mistake, for example when switching a method from private to public visibility. When this happens it should be discussed over a PR on a case-by-case basis and never committed directly to docrails.
|
311
|
+
|
312
|
+
To summarize, the Rails team uses `:nodoc:` to mark publicly visible methods and classes for internal use; changes to the visibility of API should be considered carefully and discussed over a Pull Request first.
|
313
|
+
|
314
|
+
For whatever reason, you have a question on how the Rails team handles certain API don't hesitate to open a ticket or send a patch to the [issue tracker](https://github.com/rails/rails/issues).
|
315
|
+
|
@@ -245,7 +245,7 @@ When a file is referenced from a manifest or a helper, Sprockets searches the
|
|
245
245
|
three default asset locations for it.
|
246
246
|
|
247
247
|
The default locations are: the `images`, `javascripts` and `stylesheets`
|
248
|
-
directories under the `
|
248
|
+
directories under the `app/assets` folder, but these subdirectories
|
249
249
|
are not special - any path under `assets/*` will be searched.
|
250
250
|
|
251
251
|
For example, these files:
|
@@ -691,7 +691,7 @@ information on compiling locally.
|
|
691
691
|
The rake task is:
|
692
692
|
|
693
693
|
```bash
|
694
|
-
$ RAILS_ENV=production
|
694
|
+
$ RAILS_ENV=production bin/rake assets:precompile
|
695
695
|
```
|
696
696
|
|
697
697
|
Capistrano (v2.15.1 and above) includes a recipe to handle this in deployment.
|
@@ -724,17 +724,17 @@ JS/CSS is excluded, as well as raw JS/CSS files; for example, `.coffee` and
|
|
724
724
|
`.scss` files are **not** automatically included as they compile to JS/CSS.
|
725
725
|
|
726
726
|
If you have other manifests or individual stylesheets and JavaScript files to
|
727
|
-
include, you can add them to the `precompile` array in `config/
|
727
|
+
include, you can add them to the `precompile` array in `config/initializers/assets.rb`:
|
728
728
|
|
729
729
|
```ruby
|
730
|
-
config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
|
730
|
+
Rails.application.config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
|
731
731
|
```
|
732
732
|
|
733
733
|
Or, you can opt to precompile all assets with something like this:
|
734
734
|
|
735
735
|
```ruby
|
736
|
-
# config/
|
737
|
-
config.assets.precompile << Proc.new do |path|
|
736
|
+
# config/initializers/assets.rb
|
737
|
+
Rails.application.config.assets.precompile << Proc.new do |path|
|
738
738
|
if path =~ /\.(css|js)\z/
|
739
739
|
full_path = Rails.application.assets.resolve(path).to_path
|
740
740
|
app_assets_path = Rails.root.join('app', 'assets').to_path
|
@@ -60,7 +60,7 @@ With no further work, `rails server` will run our new shiny Rails app:
|
|
60
60
|
|
61
61
|
```bash
|
62
62
|
$ cd commandsapp
|
63
|
-
$ rails server
|
63
|
+
$ bin/rails server
|
64
64
|
=> Booting WEBrick
|
65
65
|
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
|
66
66
|
=> Call with -d to detach
|
@@ -77,7 +77,7 @@ INFO: You can also use the alias "s" to start the server: `rails s`.
|
|
77
77
|
The server can be run on a different port using the `-p` option. The default development environment can be changed using `-e`.
|
78
78
|
|
79
79
|
```bash
|
80
|
-
$ rails server -e production -p 4000
|
80
|
+
$ bin/rails server -e production -p 4000
|
81
81
|
```
|
82
82
|
|
83
83
|
The `-b` option binds Rails to the specified IP, by default it is 0.0.0.0. You can run a server as a daemon by passing a `-d` option.
|
@@ -89,7 +89,7 @@ The `rails generate` command uses templates to create a whole lot of things. Run
|
|
89
89
|
INFO: You can also use the alias "g" to invoke the generator command: `rails g`.
|
90
90
|
|
91
91
|
```bash
|
92
|
-
$ rails generate
|
92
|
+
$ bin/rails generate
|
93
93
|
Usage: rails generate GENERATOR [args] [options]
|
94
94
|
|
95
95
|
...
|
@@ -114,7 +114,7 @@ Let's make our own controller with the controller generator. But what command sh
|
|
114
114
|
INFO: All Rails console utilities have help text. As with most *nix utilities, you can try adding `--help` or `-h` to the end, for example `rails server --help`.
|
115
115
|
|
116
116
|
```bash
|
117
|
-
$ rails generate controller
|
117
|
+
$ bin/rails generate controller
|
118
118
|
Usage: rails generate controller NAME [action action] [options]
|
119
119
|
|
120
120
|
...
|
@@ -141,7 +141,7 @@ Example:
|
|
141
141
|
The controller generator is expecting parameters in the form of `generate controller ControllerName action1 action2`. Let's make a `Greetings` controller with an action of **hello**, which will say something nice to us.
|
142
142
|
|
143
143
|
```bash
|
144
|
-
$ rails generate controller Greetings hello
|
144
|
+
$ bin/rails generate controller Greetings hello
|
145
145
|
create app/controllers/greetings_controller.rb
|
146
146
|
route get "greetings/hello"
|
147
147
|
invoke erb
|
@@ -182,7 +182,7 @@ Then the view, to display our message (in `app/views/greetings/hello.html.erb`):
|
|
182
182
|
Fire up your server using `rails server`.
|
183
183
|
|
184
184
|
```bash
|
185
|
-
$ rails server
|
185
|
+
$ bin/rails server
|
186
186
|
=> Booting WEBrick...
|
187
187
|
```
|
188
188
|
|
@@ -193,7 +193,7 @@ INFO: With a normal, plain-old Rails application, your URLs will generally follo
|
|
193
193
|
Rails comes with a generator for data models too.
|
194
194
|
|
195
195
|
```bash
|
196
|
-
$ rails generate model
|
196
|
+
$ bin/rails generate model
|
197
197
|
Usage:
|
198
198
|
rails generate model NAME [field[:type][:index] field[:type][:index]] [options]
|
199
199
|
|
@@ -216,7 +216,7 @@ But instead of generating a model directly (which we'll be doing later), let's s
|
|
216
216
|
We will set up a simple resource called "HighScore" that will keep track of our highest score on video games we play.
|
217
217
|
|
218
218
|
```bash
|
219
|
-
$ rails generate scaffold HighScore game:string score:integer
|
219
|
+
$ bin/rails generate scaffold HighScore game:string score:integer
|
220
220
|
invoke active_record
|
221
221
|
create db/migrate/20130717151933_create_high_scores.rb
|
222
222
|
create app/models/high_score.rb
|
@@ -257,7 +257,7 @@ The generator checks that there exist the directories for models, controllers, h
|
|
257
257
|
The migration requires that we **migrate**, that is, run some Ruby code (living in that `20130717151933_create_high_scores.rb`) to modify the schema of our database. Which database? The sqlite3 database that Rails will create for you when we run the `rake db:migrate` command. We'll talk more about Rake in-depth in a little while.
|
258
258
|
|
259
259
|
```bash
|
260
|
-
$ rake db:migrate
|
260
|
+
$ bin/rake db:migrate
|
261
261
|
== CreateHighScores: migrating ===============================================
|
262
262
|
-- create_table(:high_scores)
|
263
263
|
-> 0.0017s
|
@@ -269,7 +269,7 @@ INFO: Let's talk about unit tests. Unit tests are code that tests and makes asse
|
|
269
269
|
Let's see the interface Rails created for us.
|
270
270
|
|
271
271
|
```bash
|
272
|
-
$ rails server
|
272
|
+
$ bin/rails server
|
273
273
|
```
|
274
274
|
|
275
275
|
Go to your browser and open [http://localhost:3000/high_scores](http://localhost:3000/high_scores), now we can create new high scores (55,160 on Space Invaders!)
|
@@ -283,13 +283,13 @@ INFO: You can also use the alias "c" to invoke the console: `rails c`.
|
|
283
283
|
You can specify the environment in which the `console` command should operate.
|
284
284
|
|
285
285
|
```bash
|
286
|
-
$ rails console staging
|
286
|
+
$ bin/rails console staging
|
287
287
|
```
|
288
288
|
|
289
289
|
If you wish to test out some code without changing any data, you can do that by invoking `rails console --sandbox`.
|
290
290
|
|
291
291
|
```bash
|
292
|
-
$ rails console --sandbox
|
292
|
+
$ bin/rails console --sandbox
|
293
293
|
Loading development environment in sandbox (Rails 4.0.0)
|
294
294
|
Any modifications you make will be rolled back on exit
|
295
295
|
irb(main):001:0>
|
@@ -306,7 +306,7 @@ INFO: You can also use the alias "db" to invoke the dbconsole: `rails db`.
|
|
306
306
|
`runner` runs Ruby code in the context of Rails non-interactively. For instance:
|
307
307
|
|
308
308
|
```bash
|
309
|
-
$ rails runner "Model.long_running_method"
|
309
|
+
$ bin/rails runner "Model.long_running_method"
|
310
310
|
```
|
311
311
|
|
312
312
|
INFO: You can also use the alias "r" to invoke the runner: `rails r`.
|
@@ -314,7 +314,7 @@ INFO: You can also use the alias "r" to invoke the runner: `rails r`.
|
|
314
314
|
You can specify the environment in which the `runner` command should operate using the `-e` switch.
|
315
315
|
|
316
316
|
```bash
|
317
|
-
$ rails runner -e staging "Model.long_running_method"
|
317
|
+
$ bin/rails runner -e staging "Model.long_running_method"
|
318
318
|
```
|
319
319
|
|
320
320
|
### `rails destroy`
|
@@ -324,7 +324,7 @@ Think of `destroy` as the opposite of `generate`. It'll figure out what generate
|
|
324
324
|
INFO: You can also use the alias "d" to invoke the destroy command: `rails d`.
|
325
325
|
|
326
326
|
```bash
|
327
|
-
$ rails generate model Oops
|
327
|
+
$ bin/rails generate model Oops
|
328
328
|
invoke active_record
|
329
329
|
create db/migrate/20120528062523_create_oops.rb
|
330
330
|
create app/models/oops.rb
|
@@ -333,7 +333,7 @@ $ rails generate model Oops
|
|
333
333
|
create test/fixtures/oops.yml
|
334
334
|
```
|
335
335
|
```bash
|
336
|
-
$ rails destroy model Oops
|
336
|
+
$ bin/rails destroy model Oops
|
337
337
|
invoke active_record
|
338
338
|
remove db/migrate/20120528062523_create_oops.rb
|
339
339
|
remove app/models/oops.rb
|
@@ -353,7 +353,7 @@ To get the full backtrace for running rake task you can pass the option
|
|
353
353
|
```--trace``` to command line, for example ```rake db:create --trace```.
|
354
354
|
|
355
355
|
```bash
|
356
|
-
$ rake --tasks
|
356
|
+
$ bin/rake --tasks
|
357
357
|
rake about # List versions of all Rails frameworks and the environment
|
358
358
|
rake assets:clean # Remove compiled assets
|
359
359
|
rake assets:precompile # Compile all the assets named in config.assets.precompile
|
@@ -372,18 +372,18 @@ INFO: You can also use ```rake -T``` to get the list of tasks.
|
|
372
372
|
`rake about` gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version. It is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.
|
373
373
|
|
374
374
|
```bash
|
375
|
-
$ rake about
|
375
|
+
$ bin/rake about
|
376
376
|
About your application's environment
|
377
377
|
Ruby version 1.9.3 (x86_64-linux)
|
378
378
|
RubyGems version 1.3.6
|
379
379
|
Rack version 1.3
|
380
|
-
Rails version 4.1.
|
380
|
+
Rails version 4.1.1
|
381
381
|
JavaScript Runtime Node.js (V8)
|
382
|
-
Active Record version 4.1.
|
383
|
-
Action Pack version 4.1.
|
384
|
-
Action View version 4.1.
|
385
|
-
Action Mailer version 4.1.
|
386
|
-
Active Support version 4.1.
|
382
|
+
Active Record version 4.1.1
|
383
|
+
Action Pack version 4.1.1
|
384
|
+
Action View version 4.1.1
|
385
|
+
Action Mailer version 4.1.1
|
386
|
+
Active Support version 4.1.1
|
387
387
|
Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd131a7c88>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
|
388
388
|
Application root /home/foobar/commandsapp
|
389
389
|
Environment development
|
@@ -414,7 +414,7 @@ The `doc:` namespace has the tools to generate documentation for your app, API d
|
|
414
414
|
`rake notes` will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension `.builder`, `.rb`, `.erb`, `.haml` and `.slim` for both default and custom annotations.
|
415
415
|
|
416
416
|
```bash
|
417
|
-
$ rake notes
|
417
|
+
$ bin/rake notes
|
418
418
|
(in /home/foobar/commandsapp)
|
419
419
|
app/controllers/admin/users_controller.rb:
|
420
420
|
* [ 20] [TODO] any other way to do this?
|
@@ -428,7 +428,7 @@ app/models/school.rb:
|
|
428
428
|
If you are looking for a specific annotation, say FIXME, you can use `rake notes:fixme`. Note that you have to lower case the annotation's name.
|
429
429
|
|
430
430
|
```bash
|
431
|
-
$ rake notes:fixme
|
431
|
+
$ bin/rake notes:fixme
|
432
432
|
(in /home/foobar/commandsapp)
|
433
433
|
app/controllers/admin/users_controller.rb:
|
434
434
|
* [132] high priority for next deploy
|
@@ -440,7 +440,7 @@ app/models/school.rb:
|
|
440
440
|
You can also use custom annotations in your code and list them using `rake notes:custom` by specifying the annotation using an environment variable `ANNOTATION`.
|
441
441
|
|
442
442
|
```bash
|
443
|
-
$ rake notes:custom ANNOTATION=BUG
|
443
|
+
$ bin/rake notes:custom ANNOTATION=BUG
|
444
444
|
(in /home/foobar/commandsapp)
|
445
445
|
app/models/post.rb:
|
446
446
|
* [ 23] Have to fix this one before pushing!
|
@@ -452,7 +452,7 @@ By default, `rake notes` will look in the `app`, `config`, `lib`, `bin` and `tes
|
|
452
452
|
|
453
453
|
```bash
|
454
454
|
$ export SOURCE_ANNOTATION_DIRECTORIES='spec,vendor'
|
455
|
-
$ rake notes
|
455
|
+
$ bin/rake notes
|
456
456
|
(in /home/foobar/commandsapp)
|
457
457
|
app/models/user.rb:
|
458
458
|
* [ 35] [FIXME] User should have a subscription at this point
|
@@ -524,9 +524,9 @@ end
|
|
524
524
|
Invocation of the tasks will look like:
|
525
525
|
|
526
526
|
```bash
|
527
|
-
rake task_name
|
528
|
-
rake "task_name[value 1]" # entire argument string should be quoted
|
529
|
-
rake db:nothing
|
527
|
+
$ bin/rake task_name
|
528
|
+
$ bin/rake "task_name[value 1]" # entire argument string should be quoted
|
529
|
+
$ bin/rake db:nothing
|
530
530
|
```
|
531
531
|
|
532
532
|
NOTE: If your need to interact with your application models, perform database queries and so on, your task should depend on the `environment` task, which will load your application code.
|