rails 4.0.0 → 4.2.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +30 -23
- data/guides/CHANGELOG.md +108 -6
- data/guides/Rakefile +21 -6
- data/guides/assets/images/akshaysurve.jpg +0 -0
- data/guides/assets/images/edge_badge.png +0 -0
- data/guides/assets/images/feature_tile.gif +0 -0
- data/guides/assets/images/footer_tile.gif +0 -0
- data/guides/assets/images/fxn.png +0 -0
- data/guides/assets/images/getting_started/article_with_comments.png +0 -0
- data/guides/assets/images/getting_started/challenge.png +0 -0
- data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
- data/guides/assets/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
- data/guides/assets/images/getting_started/form_with_errors.png +0 -0
- data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
- data/guides/assets/images/getting_started/new_article.png +0 -0
- data/guides/assets/images/getting_started/rails_welcome.png +0 -0
- data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
- data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
- data/guides/assets/images/getting_started/show_action_for_articles.png +0 -0
- data/guides/assets/images/getting_started/template_is_missing_articles_new.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_create_for_articles.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_new_for_articles.png +0 -0
- data/guides/assets/images/header_tile.gif +0 -0
- data/guides/assets/images/icons/README +1 -1
- data/guides/assets/images/icons/callouts/11.png +0 -0
- data/guides/assets/images/icons/callouts/12.png +0 -0
- data/guides/assets/images/icons/callouts/13.png +0 -0
- data/guides/assets/images/icons/callouts/15.png +0 -0
- data/guides/assets/images/icons/caution.png +0 -0
- data/guides/assets/images/icons/example.png +0 -0
- data/guides/assets/images/radar.png +0 -0
- data/guides/assets/images/rails4_features.png +0 -0
- data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
- data/guides/assets/images/vijaydev.jpg +0 -0
- data/guides/assets/javascripts/guides.js +36 -34
- data/guides/assets/stylesheets/main.css +6 -2
- data/guides/assets/stylesheets/print.css +1 -1
- data/guides/bug_report_templates/action_controller_gem.rb +47 -0
- data/guides/bug_report_templates/action_controller_master.rb +54 -0
- data/guides/bug_report_templates/active_record_gem.rb +5 -2
- data/guides/bug_report_templates/active_record_master.rb +3 -2
- data/guides/bug_report_templates/generic_gem.rb +15 -0
- data/guides/bug_report_templates/generic_master.rb +26 -0
- data/guides/rails_guides.rb +23 -4
- data/guides/rails_guides/generator.rb +1 -1
- data/guides/rails_guides/helpers.rb +4 -2
- data/guides/rails_guides/levenshtein.rb +27 -21
- data/guides/rails_guides/markdown.rb +11 -7
- data/guides/rails_guides/markdown/renderer.rb +1 -1
- data/guides/source/2_2_release_notes.md +3 -3
- data/guides/source/2_3_release_notes.md +12 -12
- data/guides/source/3_0_release_notes.md +10 -13
- data/guides/source/3_1_release_notes.md +7 -4
- data/guides/source/3_2_release_notes.md +17 -14
- data/guides/source/4_0_release_notes.md +110 -54
- data/guides/source/4_1_release_notes.md +730 -0
- data/guides/source/4_2_release_notes.md +877 -0
- data/guides/source/_license.html.erb +1 -1
- data/guides/source/_welcome.html.erb +6 -2
- data/guides/source/action_controller_overview.md +223 -57
- data/guides/source/action_mailer_basics.md +129 -76
- data/guides/source/action_view_overview.md +247 -246
- data/guides/source/active_job_basics.md +339 -0
- data/guides/source/active_model_basics.md +374 -20
- data/guides/source/active_record_basics.md +46 -45
- data/guides/source/active_record_callbacks.md +83 -28
- data/guides/source/{migrations.md → active_record_migrations.md} +191 -275
- data/guides/source/active_record_postgresql.md +433 -0
- data/guides/source/active_record_querying.md +382 -300
- data/guides/source/active_record_validations.md +64 -55
- data/guides/source/active_support_core_extensions.md +229 -187
- data/guides/source/active_support_instrumentation.md +23 -22
- data/guides/source/api_documentation_guidelines.md +167 -15
- data/guides/source/asset_pipeline.md +768 -294
- data/guides/source/association_basics.md +188 -96
- data/guides/source/autoloading_and_reloading_constants.md +1311 -0
- data/guides/source/caching_with_rails.md +45 -11
- data/guides/source/command_line.md +96 -65
- data/guides/source/configuring.md +404 -70
- data/guides/source/contributing_to_ruby_on_rails.md +270 -130
- data/guides/source/credits.html.erb +7 -3
- data/guides/source/debugging_rails_applications.md +471 -284
- data/guides/source/development_dependencies_install.md +115 -21
- data/guides/source/documents.yaml +31 -9
- data/guides/source/engines.md +737 -291
- data/guides/source/form_helpers.md +137 -89
- data/guides/source/generators.md +60 -28
- data/guides/source/getting_started.md +1007 -596
- data/guides/source/i18n.md +178 -96
- data/guides/source/index.html.erb +2 -1
- data/guides/source/initialization.md +248 -104
- data/guides/source/kindle/toc.html.erb +1 -1
- data/guides/source/layout.html.erb +14 -22
- data/guides/source/layouts_and_rendering.md +78 -46
- data/guides/source/maintenance_policy.md +78 -0
- data/guides/source/nested_model_forms.md +10 -7
- data/guides/source/plugins.md +66 -57
- data/guides/source/rails_application_templates.md +49 -12
- data/guides/source/rails_on_rack.md +50 -60
- data/guides/source/routing.md +190 -139
- data/guides/source/ruby_on_rails_guides_guidelines.md +12 -13
- data/guides/source/security.md +134 -83
- data/guides/source/testing.md +322 -200
- data/guides/source/upgrading_ruby_on_rails.md +834 -37
- data/guides/source/working_with_javascript_in_rails.md +36 -26
- data/guides/w3c_validator.rb +2 -0
- metadata +93 -116
- data/guides/assets/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
- data/guides/assets/images/getting_started/new_post.png +0 -0
- data/guides/assets/images/getting_started/post_with_comments.png +0 -0
- data/guides/assets/images/getting_started/show_action_for_posts.png +0 -0
- data/guides/assets/images/getting_started/template_is_missing_posts_new.png +0 -0
- data/guides/assets/images/getting_started/undefined_method_post_path.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_new_for_posts.png +0 -0
- data/guides/assets/images/jaimeiniesta.jpg +0 -0
- data/guides/code/getting_started/Gemfile +0 -43
- data/guides/code/getting_started/Gemfile.lock +0 -150
- data/guides/code/getting_started/README.rdoc +0 -28
- data/guides/code/getting_started/Rakefile +0 -6
- data/guides/code/getting_started/app/assets/javascripts/application.js +0 -16
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
- data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
- data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -17
- data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -47
- data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
- data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
- data/guides/code/getting_started/app/models/comment.rb +0 -3
- data/guides/code/getting_started/app/models/post.rb +0 -7
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
- data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
- data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
- data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
- data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
- data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
- data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -3
- data/guides/code/getting_started/bin/bundle +0 -4
- data/guides/code/getting_started/bin/rails +0 -4
- data/guides/code/getting_started/bin/rake +0 -4
- data/guides/code/getting_started/config.ru +0 -4
- data/guides/code/getting_started/config/application.rb +0 -18
- data/guides/code/getting_started/config/boot.rb +0 -4
- data/guides/code/getting_started/config/database.yml +0 -25
- data/guides/code/getting_started/config/environment.rb +0 -5
- data/guides/code/getting_started/config/environments/development.rb +0 -30
- data/guides/code/getting_started/config/environments/production.rb +0 -80
- data/guides/code/getting_started/config/environments/test.rb +0 -36
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
- data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
- data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
- data/guides/code/getting_started/config/initializers/locale.rb +0 -9
- data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
- data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
- data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
- data/guides/code/getting_started/config/locales/en.yml +0 -23
- data/guides/code/getting_started/config/routes.rb +0 -7
- data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
- data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
- data/guides/code/getting_started/db/schema.rb +0 -33
- data/guides/code/getting_started/db/seeds.rb +0 -7
- data/guides/code/getting_started/public/404.html +0 -58
- data/guides/code/getting_started/public/422.html +0 -58
- data/guides/code/getting_started/public/500.html +0 -57
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +0 -5
- data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
- data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
- data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
- data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
- data/guides/code/getting_started/test/models/comment_test.rb +0 -7
- data/guides/code/getting_started/test/models/post_test.rb +0 -7
- data/guides/code/getting_started/test/test_helper.rb +0 -15
- data/guides/source/kindle/KINDLE.md +0 -26
@@ -11,7 +11,7 @@ After reading this guide, you will know:
|
|
11
11
|
* How to contribute to the Ruby on Rails documentation.
|
12
12
|
* How to contribute to the Ruby on Rails code.
|
13
13
|
|
14
|
-
Ruby on Rails is not "someone else's framework." Over the years, hundreds of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation
|
14
|
+
Ruby on Rails is not "someone else's framework." Over the years, hundreds of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all with the goal of making Ruby on Rails better for everyone. Even if you don't feel up to writing code or documentation yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches.
|
15
15
|
|
16
16
|
--------------------------------------------------------------------------------
|
17
17
|
|
@@ -24,18 +24,20 @@ NOTE: Bugs in the most recent released version of Ruby on Rails are likely to ge
|
|
24
24
|
|
25
25
|
### Creating a Bug Report
|
26
26
|
|
27
|
-
If you've found a problem in Ruby on Rails which is not a security risk, do a search in GitHub under [Issues](https://github.com/rails/rails/issues) in case it
|
27
|
+
If you've found a problem in Ruby on Rails which is not a security risk, do a search in GitHub under [Issues](https://github.com/rails/rails/issues) in case it has already been reported. If you do not find any issue addressing it you may proceed to [open a new one](https://github.com/rails/rails/issues/new). (See the next section for reporting security issues.)
|
28
28
|
|
29
|
-
|
29
|
+
Your issue report should contain a title and a clear description of the issue at the bare minimum. You should include as much relevant information as possible and should at least post a code sample that demonstrates the issue. It would be even better if you could include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself - and others - to replicate the bug and figure out a fix.
|
30
30
|
|
31
31
|
Then, don't get your hopes up! Unless you have a "Code Red, Mission Critical, the World is Coming to an End" kind of bug, you're creating this issue report in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the issue report will automatically see any activity or that others will jump to fix it. Creating an issue like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with an "I'm having this problem too" comment.
|
32
32
|
|
33
|
-
### Create a Self-Contained gist for Active Record Issues
|
33
|
+
### Create a Self-Contained gist for Active Record and Action Controller Issues
|
34
34
|
|
35
|
-
If you are filing a bug report
|
36
|
-
[
|
35
|
+
If you are filing a bug report, please use
|
36
|
+
[Active Record template for gems](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb) or
|
37
|
+
[Action Controller template for gems](https://github.com/rails/rails/blob/master/guides/bug_report_templates/action_controller_gem.rb)
|
37
38
|
if the bug is found in a published gem, and
|
38
|
-
[
|
39
|
+
[Active Record template for master](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_master.rb) or
|
40
|
+
[Action Controller template for master](https://github.com/rails/rails/blob/master/guides/bug_report_templates/action_controller_master.rb)
|
39
41
|
if the bug happens in the master branch.
|
40
42
|
|
41
43
|
### Special Treatment for Security Issues
|
@@ -44,93 +46,29 @@ WARNING: Please do not report security vulnerabilities with public GitHub issue
|
|
44
46
|
|
45
47
|
### What about Feature Requests?
|
46
48
|
|
47
|
-
Please don't put "feature request" items into GitHub Issues. If there's a new
|
49
|
+
Please don't put "feature request" items into GitHub Issues. If there's a new
|
50
|
+
feature that you want to see added to Ruby on Rails, you'll need to write the
|
51
|
+
code yourself - or convince someone else to partner with you to write the code.
|
52
|
+
Later in this guide you'll find detailed instructions for proposing a patch to
|
53
|
+
Ruby on Rails. If you enter a wish list item in GitHub Issues with no code, you
|
54
|
+
can expect it to be marked "invalid" as soon as it's reviewed.
|
55
|
+
|
56
|
+
Sometimes, the line between 'bug' and 'feature' is a hard one to draw.
|
57
|
+
Generally, a feature is anything that adds new behavior, while a bug is
|
58
|
+
anything that fixes already existing behavior that is misbehaving. Sometimes,
|
59
|
+
the core team will have to make a judgement call. That said, the distinction
|
60
|
+
generally just affects which release your patch will get in to; we love feature
|
61
|
+
submissions! They just won't get backported to maintenance branches.
|
62
|
+
|
63
|
+
If you'd like feedback on an idea for a feature before doing the work for make
|
64
|
+
a patch, please send an email to the [rails-core mailing
|
65
|
+
list](https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core). You
|
66
|
+
might get no response, which means that everyone is indifferent. You might find
|
67
|
+
someone who's also interested in building that feature. You might get a "This
|
68
|
+
won't be accepted." But it's the proper place to discuss new ideas. GitHub
|
69
|
+
Issues are not a particularly good venue for the sometimes long and involved
|
70
|
+
discussions new features require.
|
48
71
|
|
49
|
-
If you'd like feedback on an idea for a feature before doing the work for make a patch, please send an email to the [rails-core mailing list](https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core). You might get no response, which means that everyone is indifferent. You might find someone who's also interested in building that feature. You might get a "This won't be accepted." But it's the proper place to discuss new ideas. GitHub Issues are not a particularly good venue for the sometimes long and involved discussions new features require.
|
50
|
-
|
51
|
-
Setting Up a Development Environment
|
52
|
-
------------------------------------
|
53
|
-
|
54
|
-
To move on from submitting bugs to helping resolve existing issues or contributing your own code to Ruby on Rails, you _must_ be able to run its test suite. In this section of the guide you'll learn how to set up the tests on your own computer.
|
55
|
-
|
56
|
-
### The Easy Way
|
57
|
-
|
58
|
-
The easiest and recommended way to get a development environment ready to hack is to use the [Rails development box](https://github.com/rails/rails-dev-box).
|
59
|
-
|
60
|
-
### The Hard Way
|
61
|
-
|
62
|
-
In case you can't use the Rails development box, see section above, check [this other guide](development_dependencies_install.html).
|
63
|
-
|
64
|
-
|
65
|
-
Running an Application Against Your Local Branch
|
66
|
-
------------------------------------------------
|
67
|
-
|
68
|
-
The `--dev` flag of `rails new` generates an application that uses your local
|
69
|
-
branch:
|
70
|
-
|
71
|
-
```bash
|
72
|
-
$ cd rails
|
73
|
-
$ bundle exec rails new ~/my-test-app --dev
|
74
|
-
```
|
75
|
-
|
76
|
-
The application generated in `~/my-test-app` runs against your local branch
|
77
|
-
and in particular sees any modifications upon server reboot.
|
78
|
-
|
79
|
-
|
80
|
-
Testing Active Record
|
81
|
-
---------------------
|
82
|
-
|
83
|
-
This is how you run the Active Record test suite only for SQLite3:
|
84
|
-
|
85
|
-
```bash
|
86
|
-
$ cd activerecord
|
87
|
-
$ bundle exec rake test_sqlite3
|
88
|
-
```
|
89
|
-
|
90
|
-
You can now run the tests as you did for `sqlite3`. The tasks are respectively
|
91
|
-
|
92
|
-
```bash
|
93
|
-
test_mysql
|
94
|
-
test_mysql2
|
95
|
-
test_postgresql
|
96
|
-
```
|
97
|
-
|
98
|
-
Finally,
|
99
|
-
|
100
|
-
```bash
|
101
|
-
$ bundle exec rake test
|
102
|
-
```
|
103
|
-
|
104
|
-
will now run the four of them in turn.
|
105
|
-
|
106
|
-
You can also run any single test separately:
|
107
|
-
|
108
|
-
```bash
|
109
|
-
$ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb
|
110
|
-
```
|
111
|
-
|
112
|
-
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.
|
113
|
-
|
114
|
-
### Warnings
|
115
|
-
|
116
|
-
The test suite runs with warnings enabled. Ideally, Ruby on Rails should issue no warnings, but there may be a few, as well as some from third-party libraries. Please ignore (or fix!) them, if any, and submit patches that do not issue new warnings.
|
117
|
-
|
118
|
-
As of this writing (December, 2010) they are especially noisy with Ruby 1.9. If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag:
|
119
|
-
|
120
|
-
```bash
|
121
|
-
$ RUBYOPT=-W0 bundle exec rake test
|
122
|
-
```
|
123
|
-
|
124
|
-
### Older Versions of Ruby on Rails
|
125
|
-
|
126
|
-
If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 3-0-stable branch:
|
127
|
-
|
128
|
-
```bash
|
129
|
-
$ git branch --track 3-0-stable origin/3-0-stable
|
130
|
-
$ git checkout 3-0-stable
|
131
|
-
```
|
132
|
-
|
133
|
-
TIP: You may want to [put your Git branch name in your shell prompt](http://qugstart.com/blog/git-and-svn/add-colored-git-branch-name-to-your-shell-prompt/) to make it easier to remember which version of the code you're working with.
|
134
72
|
|
135
73
|
Helping to Resolve Existing Issues
|
136
74
|
----------------------------------
|
@@ -171,20 +109,25 @@ After applying their branch, test it out! Here are some things to think about:
|
|
171
109
|
|
172
110
|
Once you're happy that the pull request contains a good change, comment on the GitHub issue indicating your approval. Your comment should indicate that you like the change and what you like about it. Something like:
|
173
111
|
|
174
|
-
|
175
|
-
I like the way you've restructured that code in generate_finder_sql — much nicer. The tests look good too.
|
176
|
-
</blockquote>
|
112
|
+
>I like the way you've restructured that code in generate_finder_sql - much nicer. The tests look good too.
|
177
113
|
|
178
114
|
If your comment simply says "+1", then odds are that other reviewers aren't going to take it too seriously. Show that you took the time to review the pull request.
|
179
115
|
|
180
116
|
Contributing to the Rails Documentation
|
181
117
|
---------------------------------------
|
182
118
|
|
183
|
-
Ruby on Rails has two main sets of documentation: the guides help you
|
119
|
+
Ruby on Rails has two main sets of documentation: the guides, which help you
|
120
|
+
learn about Ruby on Rails, and the API, which serves as a reference.
|
121
|
+
|
122
|
+
You can help improve the Rails guides by making them more coherent, consistent or readable, adding missing information, correcting factual errors, fixing typos, or bringing it up to date with the latest edge Rails.
|
184
123
|
|
185
|
-
You can
|
124
|
+
You can either open a pull request to [Rails](http://github.com/rails/rails) or
|
125
|
+
ask the [Rails core team](http://rubyonrails.org/core) for commit access on
|
126
|
+
docrails if you contribute regularly.
|
127
|
+
Please do not open pull requests in docrails, if you'd like to get feedback on your
|
128
|
+
change, ask for it in [Rails](http://github.com/rails/rails) instead.
|
186
129
|
|
187
|
-
|
130
|
+
Docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation.
|
188
131
|
|
189
132
|
If you are unsure of the documentation changes, you can create an issue in the [Rails](https://github.com/rails/rails/issues) issues tracker on GitHub.
|
190
133
|
|
@@ -192,16 +135,28 @@ When working with documentation, please take into account the [API Documentation
|
|
192
135
|
|
193
136
|
NOTE: As explained earlier, ordinary code patches should have proper documentation coverage. Docrails is only used for isolated documentation improvements.
|
194
137
|
|
195
|
-
NOTE: To help our CI servers you
|
138
|
+
NOTE: To help our CI servers you should add [ci skip] to your documentation commit message to skip build on that commit. Please remember to use it for commits containing only documentation changes.
|
196
139
|
|
197
140
|
WARNING: Docrails has a very strict policy: no code can be touched whatsoever, no matter how trivial or small the change. Only RDoc and guides can be edited via docrails. Also, CHANGELOGs should never be edited in docrails.
|
198
141
|
|
199
142
|
Contributing to the Rails Code
|
200
143
|
------------------------------
|
201
144
|
|
145
|
+
### Setting Up a Development Environment
|
146
|
+
|
147
|
+
To move on from submitting bugs to helping resolve existing issues or contributing your own code to Ruby on Rails, you _must_ be able to run its test suite. In this section of the guide you'll learn how to setup the tests on your own computer.
|
148
|
+
|
149
|
+
#### The Easy Way
|
150
|
+
|
151
|
+
The easiest and recommended way to get a development environment ready to hack is to use the [Rails development box](https://github.com/rails/rails-dev-box).
|
152
|
+
|
153
|
+
#### The Hard Way
|
154
|
+
|
155
|
+
In case you can't use the Rails development box, see [this other guide](development_dependencies_install.html).
|
156
|
+
|
202
157
|
### Clone the Rails Repository
|
203
158
|
|
204
|
-
|
159
|
+
To be able to contribute code, you need to clone the Rails repository:
|
205
160
|
|
206
161
|
```bash
|
207
162
|
$ git clone git://github.com/rails/rails.git
|
@@ -214,31 +169,33 @@ $ cd rails
|
|
214
169
|
$ git checkout -b my_new_branch
|
215
170
|
```
|
216
171
|
|
217
|
-
It doesn
|
172
|
+
It doesn't matter much what name you use, because this branch will only exist on your local computer and your personal repository on GitHub. It won't be part of the Rails Git repository.
|
173
|
+
|
174
|
+
### Running an Application Against Your Local Branch
|
175
|
+
|
176
|
+
In case you need a dummy Rails app to test changes, the `--dev` flag of `rails new` generates an application that uses your local branch:
|
177
|
+
|
178
|
+
```bash
|
179
|
+
$ cd rails
|
180
|
+
$ bundle exec rails new ~/my-test-app --dev
|
181
|
+
```
|
182
|
+
|
183
|
+
The application generated in `~/my-test-app` runs against your local branch
|
184
|
+
and in particular sees any modifications upon server reboot.
|
218
185
|
|
219
186
|
### Write Your Code
|
220
187
|
|
221
|
-
Now get busy and add
|
188
|
+
Now get busy and add/edit code. You're on your branch now, so you can write whatever you want (make sure you're on the right branch with `git branch -a`). But if you're planning to submit your change back for inclusion in Rails, keep a few things in mind:
|
222
189
|
|
223
190
|
* Get the code right.
|
224
191
|
* Use Rails idioms and helpers.
|
225
192
|
* Include tests that fail without your code, and pass with it.
|
226
193
|
* Update the (surrounding) documentation, examples elsewhere, and the guides: whatever is affected by your contribution.
|
227
194
|
|
228
|
-
It is not customary in Rails to run the full test suite before pushing
|
229
|
-
changes. The railties test suite in particular takes a long time, and even
|
230
|
-
more if the source code is mounted in `/vagrant` as happens in the recommended
|
231
|
-
workflow with the [rails-dev-box](https://github.com/rails/rails-dev-box).
|
232
|
-
|
233
|
-
As a compromise, test what your code obviously affects, and if the change is
|
234
|
-
not in railties run the whole test suite of the affected component. If all is
|
235
|
-
green that's enough to propose your contribution. We have [Travis CI](https
|
236
|
-
://travis-ci.org/) as a safety net for catching unexpected breakages
|
237
|
-
elsewhere.
|
238
195
|
|
239
|
-
TIP: Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability of Rails will generally not be accepted.
|
196
|
+
TIP: Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability of Rails will generally not be accepted (read more about [our rationales behind this decision](https://github.com/rails/rails/pull/13771#issuecomment-32746700)).
|
240
197
|
|
241
|
-
|
198
|
+
#### Follow the Coding Conventions
|
242
199
|
|
243
200
|
Rails follows a simple set of coding style conventions:
|
244
201
|
|
@@ -254,7 +211,130 @@ Rails follows a simple set of coding style conventions:
|
|
254
211
|
* Prefer `method { do_stuff }` instead of `method{do_stuff}` for single-line blocks.
|
255
212
|
* Follow the conventions in the source you see used already.
|
256
213
|
|
257
|
-
The above are guidelines
|
214
|
+
The above are guidelines - please use your best judgment in using them.
|
215
|
+
|
216
|
+
### Benchmark Your Code
|
217
|
+
|
218
|
+
If your change has an impact on the performance of Rails, please use the
|
219
|
+
[benchmark-ips](https://github.com/evanphx/benchmark-ips) gem to provide
|
220
|
+
benchmark results for comparison.
|
221
|
+
|
222
|
+
Here's an example of using benchmark-ips:
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
require 'benchmark/ips'
|
226
|
+
|
227
|
+
Benchmark.ips do |x|
|
228
|
+
x.report('addition') { 1 + 2 }
|
229
|
+
x.report('addition with send') { 1.send(:+, 2) }
|
230
|
+
end
|
231
|
+
```
|
232
|
+
|
233
|
+
This will generate a report with the following information:
|
234
|
+
|
235
|
+
```
|
236
|
+
Calculating -------------------------------------
|
237
|
+
addition 69114 i/100ms
|
238
|
+
addition with send 64062 i/100ms
|
239
|
+
-------------------------------------------------
|
240
|
+
addition 5307644.4 (±3.5%) i/s - 26539776 in 5.007219s
|
241
|
+
addition with send 3702897.9 (±3.5%) i/s - 18513918 in 5.006723s
|
242
|
+
```
|
243
|
+
|
244
|
+
Please see the benchmark/ips [README](https://github.com/evanphx/benchmark-ips/blob/master/README.md) for more information.
|
245
|
+
|
246
|
+
### Running Tests
|
247
|
+
|
248
|
+
It is not customary in Rails to run the full test suite before pushing
|
249
|
+
changes. The railties test suite in particular takes a long time, and even
|
250
|
+
more if the source code is mounted in `/vagrant` as happens in the recommended
|
251
|
+
workflow with the [rails-dev-box](https://github.com/rails/rails-dev-box).
|
252
|
+
|
253
|
+
As a compromise, test what your code obviously affects, and if the change is
|
254
|
+
not in railties, run the whole test suite of the affected component. If all
|
255
|
+
tests are passing, that's enough to propose your contribution. We have
|
256
|
+
[Travis CI](https://travis-ci.org/rails/rails) as a safety net for catching
|
257
|
+
unexpected breakages elsewhere.
|
258
|
+
|
259
|
+
#### Entire Rails:
|
260
|
+
|
261
|
+
To run all the tests, do:
|
262
|
+
|
263
|
+
```bash
|
264
|
+
$ cd rails
|
265
|
+
$ bundle exec rake test
|
266
|
+
```
|
267
|
+
|
268
|
+
#### For a Particular Component
|
269
|
+
|
270
|
+
You can run tests only for a particular component (e.g. Action Pack). For example,
|
271
|
+
to run Action Mailer tests:
|
272
|
+
|
273
|
+
```bash
|
274
|
+
$ cd actionmailer
|
275
|
+
$ bundle exec rake test
|
276
|
+
```
|
277
|
+
|
278
|
+
#### Running a Single Test
|
279
|
+
|
280
|
+
You can run a single test through ruby. For instance:
|
281
|
+
|
282
|
+
```bash
|
283
|
+
$ cd actionmailer
|
284
|
+
$ bundle exec ruby -w -Itest test/mail_layout_test.rb -n test_explicit_class_layout
|
285
|
+
```
|
286
|
+
|
287
|
+
The `-n` option allows you to run a single method instead of the whole
|
288
|
+
file.
|
289
|
+
|
290
|
+
##### Testing Active Record
|
291
|
+
|
292
|
+
This is how you run the Active Record test suite only for SQLite3:
|
293
|
+
|
294
|
+
```bash
|
295
|
+
$ cd activerecord
|
296
|
+
$ bundle exec rake test:sqlite3
|
297
|
+
```
|
298
|
+
|
299
|
+
You can now run the tests as you did for `sqlite3`. The tasks are respectively
|
300
|
+
|
301
|
+
```bash
|
302
|
+
test:mysql
|
303
|
+
test:mysql2
|
304
|
+
test:postgresql
|
305
|
+
```
|
306
|
+
|
307
|
+
Finally,
|
308
|
+
|
309
|
+
```bash
|
310
|
+
$ bundle exec rake test
|
311
|
+
```
|
312
|
+
|
313
|
+
will now run the four of them in turn.
|
314
|
+
|
315
|
+
You can also run any single test separately:
|
316
|
+
|
317
|
+
```bash
|
318
|
+
$ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb
|
319
|
+
```
|
320
|
+
|
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
|
+
|
327
|
+
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.
|
328
|
+
|
329
|
+
### Warnings
|
330
|
+
|
331
|
+
The test suite runs with warnings enabled. Ideally, Ruby on Rails should issue no warnings, but there may be a few, as well as some from third-party libraries. Please ignore (or fix!) them, if any, and submit patches that do not issue new warnings.
|
332
|
+
|
333
|
+
If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag:
|
334
|
+
|
335
|
+
```bash
|
336
|
+
$ RUBYOPT=-W0 bundle exec rake test
|
337
|
+
```
|
258
338
|
|
259
339
|
### Updating the CHANGELOG
|
260
340
|
|
@@ -262,7 +342,7 @@ The CHANGELOG is an important part of every release. It keeps the list of change
|
|
262
342
|
|
263
343
|
You should add an entry to the CHANGELOG of the framework that you modified if you're adding or removing a feature, committing a bug fix or adding deprecation notices. Refactorings and documentation changes generally should not go to the CHANGELOG.
|
264
344
|
|
265
|
-
A CHANGELOG entry should summarize what was changed and should end with author's name. You can use multiple lines if you need more space and you can attach code examples indented with 4 spaces. If a change is related to a specific issue, you should attach issue's number. Here is an example CHANGELOG entry:
|
345
|
+
A CHANGELOG entry should summarize what was changed and should end with author's name and it should go on top of a CHANGELOG. You can use multiple lines if you need more space and you can attach code examples indented with 4 spaces. If a change is related to a specific issue, you should attach the issue's number. Here is an example CHANGELOG entry:
|
266
346
|
|
267
347
|
```
|
268
348
|
* Summary of a change that briefly describes what was changed. You can use multiple
|
@@ -281,9 +361,19 @@ A CHANGELOG entry should summarize what was changed and should end with author's
|
|
281
361
|
|
282
362
|
Your name can be added directly after the last word if you don't provide any code examples or don't need multiple paragraphs. Otherwise, it's best to make as a new paragraph.
|
283
363
|
|
364
|
+
### Updating the Gemfile.lock
|
365
|
+
|
366
|
+
Some changes requires the dependencies to be upgraded. In these cases make sure you run `bundle update` to get the right version of the dependency and commit the `Gemfile.lock` file within your changes.
|
367
|
+
|
284
368
|
### Sanity Check
|
285
369
|
|
286
|
-
You should not be the only person who looks at the code before you submit it.
|
370
|
+
You should not be the only person who looks at the code before you submit it.
|
371
|
+
If you know someone else who uses Rails, try asking them if they'll check out
|
372
|
+
your work. If you don't know anyone else using Rails, try hopping into the IRC
|
373
|
+
room or posting about your idea to the rails-core mailing list. Doing this in
|
374
|
+
private before you push a patch out publicly is the "smoke test" for a patch:
|
375
|
+
if you can't convince one other developer of the beauty of your code, you’re
|
376
|
+
unlikely to convince the core team either.
|
287
377
|
|
288
378
|
### Commit Your Changes
|
289
379
|
|
@@ -309,9 +399,9 @@ it should not be necessary to visit a webpage to check the history.
|
|
309
399
|
Description can have multiple paragraphs and you can use code examples
|
310
400
|
inside, just indent it with 4 spaces:
|
311
401
|
|
312
|
-
class
|
402
|
+
class ArticlesController
|
313
403
|
def index
|
314
|
-
|
404
|
+
render json: Article.limit(10)
|
315
405
|
end
|
316
406
|
end
|
317
407
|
|
@@ -327,7 +417,7 @@ TIP. Please squash your commits into a single commit when appropriate. This simp
|
|
327
417
|
|
328
418
|
### Update Your Branch
|
329
419
|
|
330
|
-
It
|
420
|
+
It's pretty likely that other changes to master have happened while you were working. Go get them:
|
331
421
|
|
332
422
|
```bash
|
333
423
|
$ git checkout master
|
@@ -397,25 +487,47 @@ $ git push origin branch_name
|
|
397
487
|
|
398
488
|
### Issue a Pull Request
|
399
489
|
|
400
|
-
Navigate to the Rails repository you just pushed to (e.g.
|
490
|
+
Navigate to the Rails repository you just pushed to (e.g.
|
491
|
+
https://github.com/your-user-name/rails) and click on "Pull Requests" seen in
|
492
|
+
the right panel. On the next page, press "New pull request" in the upper right
|
493
|
+
hand corner.
|
401
494
|
|
402
|
-
|
495
|
+
Click on "Edit", if you need to change the branches being compared (it compares
|
496
|
+
"master" by default) and press "Click to create a pull request for this
|
497
|
+
comparison".
|
403
498
|
|
404
|
-
Ensure the changesets you introduced are included
|
405
|
-
|
406
|
-
|
499
|
+
Ensure the changesets you introduced are included. Fill in some details about
|
500
|
+
your potential patch including a meaningful title. When finished, press "Send
|
501
|
+
pull request". The Rails core team will be notified about your submission.
|
407
502
|
|
408
503
|
### Get some Feedback
|
409
504
|
|
410
|
-
|
505
|
+
Most pull requests will go through a few iterations before they get merged.
|
506
|
+
Different contributors will sometimes have different opinions, and often
|
507
|
+
patches will need revised before they can get merged.
|
508
|
+
|
509
|
+
Some contributors to Rails have email notifications from GitHub turned on, but
|
510
|
+
others do not. Furthermore, (almost) everyone who works on Rails is a
|
511
|
+
volunteer, and so it may take a few days for you to get your first feedback on
|
512
|
+
a pull request. Don't despair! Sometimes it's quick, sometimes it's slow. Such
|
513
|
+
is the open source life.
|
514
|
+
|
515
|
+
If it's been over a week, and you haven't heard anything, you might want to try
|
516
|
+
and nudge things along. You can use the [rubyonrails-core mailing
|
517
|
+
list](http://groups.google.com/group/rubyonrails-core/) for this. You can also
|
518
|
+
leave another comment on the pull request.
|
519
|
+
|
520
|
+
While you're waiting for feedback on your pull request, open up a few other
|
521
|
+
pull requests and give someone else some! I'm sure they'll appreciate it in
|
522
|
+
the same way that you appreciate feedback on your patches.
|
411
523
|
|
412
524
|
### Iterate as Necessary
|
413
525
|
|
414
|
-
It
|
526
|
+
It's entirely possible that the feedback you get will suggest changes. Don't get discouraged: the whole point of contributing to an active open source project is to tap into the knowledge of the community. If people are encouraging you to tweak your code, then it's worth making the tweaks and resubmitting. If the feedback is that your code doesn't belong in the core, you might still think about releasing it as a gem.
|
415
527
|
|
416
528
|
#### Squashing commits
|
417
529
|
|
418
|
-
One of the things that we may ask you to do is "squash your commits,
|
530
|
+
One of the things that we may ask you to do is to "squash your commits", which
|
419
531
|
will combine all of your commits into a single commit. We prefer pull requests
|
420
532
|
that are a single commit. This makes it easier to backport changes to stable
|
421
533
|
branches, squashing makes it easier to revert bad commits, and the git history
|
@@ -451,7 +563,35 @@ $ git push origin my_pull_request -f
|
|
451
563
|
You should be able to refresh the pull request on GitHub and see that it has
|
452
564
|
been updated.
|
453
565
|
|
454
|
-
|
566
|
+
#### Updating pull request
|
567
|
+
|
568
|
+
Sometimes you will be asked to make some changes to the code you have
|
569
|
+
already committed. This can include amending existing commits. In this
|
570
|
+
case Git will not allow you to push the changes as the pushed branch
|
571
|
+
and local branch do not match. Instead of opening a new pull request,
|
572
|
+
you can force push to your branch on GitHub as described earlier in
|
573
|
+
squashing commits section:
|
574
|
+
|
575
|
+
```bash
|
576
|
+
$ git push origin my_pull_request -f
|
577
|
+
```
|
578
|
+
|
579
|
+
This will update the branch and pull request on GitHub with your new code. Do
|
580
|
+
note that using force push may result in commits being lost on the remote branch; use it with care.
|
581
|
+
|
582
|
+
|
583
|
+
### Older Versions of Ruby on Rails
|
584
|
+
|
585
|
+
If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 4-0-stable branch:
|
586
|
+
|
587
|
+
```bash
|
588
|
+
$ git branch --track 4-0-stable origin/4-0-stable
|
589
|
+
$ git checkout 4-0-stable
|
590
|
+
```
|
591
|
+
|
592
|
+
TIP: You may want to [put your Git branch name in your shell prompt](http://qugstart.com/blog/git-and-svn/add-colored-git-branch-name-to-your-shell-prompt/) to make it easier to remember which version of the code you're working with.
|
593
|
+
|
594
|
+
#### Backporting
|
455
595
|
|
456
596
|
Changes that are merged into master are intended for the next major release of Rails. Sometimes, it might be beneficial for your changes to propagate back to the maintenance releases for older stable branches. Generally, security fixes and bug fixes are good candidates for a backport, while new features and patches that introduce a change in behavior will not be accepted. When in doubt, it is best to consult a Rails team member before backporting your changes to avoid wasted effort.
|
457
597
|
|