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
@@ -1,10 +1,9 @@
|
|
1
|
-
<!DOCTYPE html
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
1
|
+
<!DOCTYPE html>
|
3
2
|
|
4
3
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
4
|
<head>
|
6
5
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1"
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
8
7
|
|
9
8
|
<title><%= yield(:page_title) || 'Ruby on Rails Guides' %></title>
|
10
9
|
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
@@ -30,15 +29,11 @@
|
|
30
29
|
More Ruby on Rails
|
31
30
|
</span>
|
32
31
|
<ul class="more-info-links s-hidden">
|
33
|
-
<li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
|
34
|
-
<li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
|
35
|
-
<li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
|
36
|
-
<li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
|
37
|
-
<li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
|
38
|
-
<li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
|
39
|
-
<li class="more-info"><a href="http://rubyonrails.org/ecosystem">Ecosystem</a></li>
|
40
|
-
<li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
|
41
32
|
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
|
33
|
+
<li class="more-info"><a href="http://guides.rubyonrails.org/">Guides</a></li>
|
34
|
+
<li class="more-info"><a href="http://api.rubyonrails.org/">API</a></li>
|
35
|
+
<li class="more-info"><a href="http://stackoverflow.com/questions/tagged/ruby-on-rails">Ask for help</a></li>
|
36
|
+
<li class="more-info"><a href="https://github.com/rails/rails">Contribute on GitHub</a></li>
|
42
37
|
</ul>
|
43
38
|
</div>
|
44
39
|
</div>
|
@@ -48,7 +43,7 @@
|
|
48
43
|
<ul class="nav">
|
49
44
|
<li><a class="nav-item" href="index.html">Home</a></li>
|
50
45
|
<li class="guides-index guides-index-large">
|
51
|
-
<a href="index.html"
|
46
|
+
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guides Index</a>
|
52
47
|
<div id="guides" class="clearfix" style="display: none;">
|
53
48
|
<hr />
|
54
49
|
<% ['L', 'R'].each do |position| %>
|
@@ -78,7 +73,6 @@
|
|
78
73
|
</select>
|
79
74
|
</li>
|
80
75
|
</ul>
|
81
|
-
</div>
|
82
76
|
</div>
|
83
77
|
</div>
|
84
78
|
<hr class="hide" />
|
@@ -101,17 +95,15 @@
|
|
101
95
|
You're encouraged to help improve the quality of this guide.
|
102
96
|
</p>
|
103
97
|
<p>
|
104
|
-
|
105
|
-
|
106
|
-
repository and open a new pull request. You can also ask for commit rights on
|
107
|
-
<%= link_to 'docrails', 'https://github.com/rails/docrails' %> if you plan to submit
|
108
|
-
several patches. Commits are reviewed, but that happens after you've submitted your
|
109
|
-
contribution. This repository is cross-merged with master periodically.
|
98
|
+
Please contribute if you see any typos or factual errors.
|
99
|
+
To get started, you can read our <%= link_to 'documentation contributions', 'http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation' %> section.
|
110
100
|
</p>
|
111
101
|
<p>
|
112
102
|
You may also find incomplete content, or stuff that is not up to date.
|
113
|
-
Please do add any missing documentation for master.
|
114
|
-
<%= link_to '
|
103
|
+
Please do add any missing documentation for master. Make sure to check
|
104
|
+
<%= link_to 'Edge Guides','http://edgeguides.rubyonrails.org' %> first to verify
|
105
|
+
if the issues are already fixed or not on the master branch.
|
106
|
+
Check the <%= link_to 'Ruby on Rails Guides Guidelines', 'ruby_on_rails_guides_guidelines.html' %>
|
115
107
|
for style and conventions.
|
116
108
|
</p>
|
117
109
|
<p>
|
@@ -141,7 +133,7 @@
|
|
141
133
|
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
142
134
|
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
143
135
|
<script type="text/javascript">
|
144
|
-
SyntaxHighlighter.all()
|
136
|
+
SyntaxHighlighter.all();
|
145
137
|
$(guidesIndex.bind);
|
146
138
|
</script>
|
147
139
|
</body>
|
@@ -88,7 +88,7 @@ If we want to display the properties of all the books in our view, we can do so
|
|
88
88
|
<% end %>
|
89
89
|
</table>
|
90
90
|
|
91
|
-
<br
|
91
|
+
<br>
|
92
92
|
|
93
93
|
<%= link_to "New book", new_book_path %>
|
94
94
|
```
|
@@ -122,8 +122,7 @@ X-Runtime: 0.014297
|
|
122
122
|
Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
|
123
123
|
Cache-Control: no-cache
|
124
124
|
|
125
|
-
|
126
|
-
$
|
125
|
+
$
|
127
126
|
```
|
128
127
|
|
129
128
|
We see there is an empty response (no data after the `Cache-Control` line), but the request was successful because Rails has set the response to 200 OK. You can set the `:status` option on render to change this response. Rendering nothing can be useful for Ajax requests where all you want to send back to the browser is an acknowledgment that the request was completed.
|
@@ -137,7 +136,7 @@ If you want to render the view that corresponds to a different template within t
|
|
137
136
|
```ruby
|
138
137
|
def update
|
139
138
|
@book = Book.find(params[:id])
|
140
|
-
if @book.update(
|
139
|
+
if @book.update(book_params)
|
141
140
|
redirect_to(@book)
|
142
141
|
else
|
143
142
|
render "edit"
|
@@ -152,7 +151,7 @@ If you prefer, you can use a symbol instead of a string to specify the action to
|
|
152
151
|
```ruby
|
153
152
|
def update
|
154
153
|
@book = Book.find(params[:id])
|
155
|
-
if @book.update(
|
154
|
+
if @book.update(book_params)
|
156
155
|
redirect_to(@book)
|
157
156
|
else
|
158
157
|
render :edit
|
@@ -176,23 +175,22 @@ render template: "products/show"
|
|
176
175
|
|
177
176
|
#### Rendering an Arbitrary File
|
178
177
|
|
179
|
-
The `render` method can also use a view that's entirely outside of your application
|
180
|
-
|
181
|
-
```ruby
|
182
|
-
render "/u/apps/warehouse_app/current/app/views/products/show"
|
183
|
-
```
|
184
|
-
|
185
|
-
Rails determines that this is a file render because of the leading slash character. To be explicit, you can use the `:file` option (which was required on Rails 2.2 and earlier):
|
178
|
+
The `render` method can also use a view that's entirely outside of your application:
|
186
179
|
|
187
180
|
```ruby
|
188
181
|
render file: "/u/apps/warehouse_app/current/app/views/products/show"
|
189
182
|
```
|
190
183
|
|
191
|
-
The `:file` option takes an absolute file-system path. Of course, you need to have rights
|
184
|
+
The `:file` option takes an absolute file-system path. Of course, you need to have rights
|
185
|
+
to the view that you're using to render the content.
|
192
186
|
|
193
|
-
NOTE:
|
187
|
+
NOTE: Using the `:file` option in combination with users input can lead to security problems
|
188
|
+
since an attacker could use this action to access security sensitive files in your file system.
|
194
189
|
|
195
|
-
|
190
|
+
NOTE: By default, the file is rendered using the current layout.
|
191
|
+
|
192
|
+
TIP: If you're running Rails on Microsoft Windows, you should use the `:file` option to
|
193
|
+
render a file, because Windows filenames do not have the same format as Unix filenames.
|
196
194
|
|
197
195
|
#### Wrapping it up
|
198
196
|
|
@@ -237,15 +235,35 @@ render inline: "xml.p {'Horrid coding practice!'}", type: :builder
|
|
237
235
|
|
238
236
|
#### Rendering Text
|
239
237
|
|
240
|
-
You can send plain text - with no markup at all - back to the browser by using
|
238
|
+
You can send plain text - with no markup at all - back to the browser by using
|
239
|
+
the `:plain` option to `render`:
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
render plain: "OK"
|
243
|
+
```
|
244
|
+
|
245
|
+
TIP: Rendering pure text is most useful when you're responding to Ajax or web
|
246
|
+
service requests that are expecting something other than proper HTML.
|
247
|
+
|
248
|
+
NOTE: By default, if you use the `:plain` option, the text is rendered without
|
249
|
+
using the current layout. If you want Rails to put the text into the current
|
250
|
+
layout, you need to add the `layout: true` option and use the `.txt.erb`
|
251
|
+
extension for the layout file.
|
252
|
+
|
253
|
+
#### Rendering HTML
|
254
|
+
|
255
|
+
You can send a HTML string back to the browser by using the `:html` option to
|
256
|
+
`render`:
|
241
257
|
|
242
258
|
```ruby
|
243
|
-
render
|
259
|
+
render html: "<strong>Not Found</strong>".html_safe
|
244
260
|
```
|
245
261
|
|
246
|
-
TIP:
|
262
|
+
TIP: This is useful when you're rendering a small snippet of HTML code.
|
263
|
+
However, you might want to consider moving it to a template file if the markup
|
264
|
+
is complex.
|
247
265
|
|
248
|
-
NOTE:
|
266
|
+
NOTE: This option will escape HTML entities if the string is not HTML safe.
|
249
267
|
|
250
268
|
#### Rendering JSON
|
251
269
|
|
@@ -277,6 +295,22 @@ render js: "alert('Hello Rails');"
|
|
277
295
|
|
278
296
|
This will send the supplied string to the browser with a MIME type of `text/javascript`.
|
279
297
|
|
298
|
+
#### Rendering raw body
|
299
|
+
|
300
|
+
You can send a raw content back to the browser, without setting any content
|
301
|
+
type, by using the `:body` option to `render`:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
render body: "raw"
|
305
|
+
```
|
306
|
+
|
307
|
+
TIP: This option should be used only if you don't care about the content type of
|
308
|
+
the response. Using `:plain` or `:html` might be more appropriate in most of the
|
309
|
+
time.
|
310
|
+
|
311
|
+
NOTE: Unless overridden, your response returned from this render option will be
|
312
|
+
`text/html`, as that is the default content type of Action Dispatch response.
|
313
|
+
|
280
314
|
#### Options for `render`
|
281
315
|
|
282
316
|
Calls to the `render` method generally accept four options:
|
@@ -375,9 +409,9 @@ Rails understands both numeric status codes and the corresponding symbols shown
|
|
375
409
|
| | 423 | :locked |
|
376
410
|
| | 424 | :failed_dependency |
|
377
411
|
| | 426 | :upgrade_required |
|
378
|
-
| |
|
379
|
-
| |
|
380
|
-
| |
|
412
|
+
| | 428 | :precondition_required |
|
413
|
+
| | 429 | :too_many_requests |
|
414
|
+
| | 431 | :request_header_fields_too_large |
|
381
415
|
| **Server Error** | 500 | :internal_server_error |
|
382
416
|
| | 501 | :not_implemented |
|
383
417
|
| | 502 | :bad_gateway |
|
@@ -405,7 +439,7 @@ class ProductsController < ApplicationController
|
|
405
439
|
end
|
406
440
|
```
|
407
441
|
|
408
|
-
With this declaration, all of the views rendered by the
|
442
|
+
With this declaration, all of the views rendered by the `ProductsController` will use `app/views/layouts/inventory.html.erb` as their layout.
|
409
443
|
|
410
444
|
To assign a specific layout for the entire application, use a `layout` declaration in your `ApplicationController` class:
|
411
445
|
|
@@ -472,33 +506,33 @@ Layout declarations cascade downward in the hierarchy, and more specific layout
|
|
472
506
|
end
|
473
507
|
```
|
474
508
|
|
475
|
-
* `
|
509
|
+
* `articles_controller.rb`
|
476
510
|
|
477
511
|
```ruby
|
478
|
-
class
|
512
|
+
class ArticlesController < ApplicationController
|
479
513
|
end
|
480
514
|
```
|
481
515
|
|
482
|
-
* `
|
516
|
+
* `special_articles_controller.rb`
|
483
517
|
|
484
518
|
```ruby
|
485
|
-
class
|
519
|
+
class SpecialArticlesController < ArticlesController
|
486
520
|
layout "special"
|
487
521
|
end
|
488
522
|
```
|
489
523
|
|
490
|
-
* `
|
524
|
+
* `old_articles_controller.rb`
|
491
525
|
|
492
526
|
```ruby
|
493
|
-
class
|
527
|
+
class OldArticlesController < SpecialArticlesController
|
494
528
|
layout false
|
495
529
|
|
496
530
|
def show
|
497
|
-
@
|
531
|
+
@article = Article.find(params[:id])
|
498
532
|
end
|
499
533
|
|
500
534
|
def index
|
501
|
-
@
|
535
|
+
@old_articles = Article.older
|
502
536
|
render layout: "old"
|
503
537
|
end
|
504
538
|
# ...
|
@@ -508,10 +542,10 @@ Layout declarations cascade downward in the hierarchy, and more specific layout
|
|
508
542
|
In this application:
|
509
543
|
|
510
544
|
* In general, views will be rendered in the `main` layout
|
511
|
-
* `
|
512
|
-
* `
|
513
|
-
* `
|
514
|
-
* `
|
545
|
+
* `ArticlesController#index` will use the `main` layout
|
546
|
+
* `SpecialArticlesController#index` will use the `special` layout
|
547
|
+
* `OldArticlesController#show` will use no layout at all
|
548
|
+
* `OldArticlesController#index` will use the `old` layout
|
515
549
|
|
516
550
|
#### Avoiding Double Render Errors
|
517
551
|
|
@@ -592,7 +626,7 @@ def index
|
|
592
626
|
end
|
593
627
|
|
594
628
|
def show
|
595
|
-
@book = Book.
|
629
|
+
@book = Book.find_by(id: params[:id])
|
596
630
|
if @book.nil?
|
597
631
|
render action: "index"
|
598
632
|
end
|
@@ -607,7 +641,7 @@ def index
|
|
607
641
|
end
|
608
642
|
|
609
643
|
def show
|
610
|
-
@book = Book.
|
644
|
+
@book = Book.find_by(id: params[:id])
|
611
645
|
if @book.nil?
|
612
646
|
redirect_to action: :index
|
613
647
|
end
|
@@ -626,10 +660,10 @@ def index
|
|
626
660
|
end
|
627
661
|
|
628
662
|
def show
|
629
|
-
@book = Book.
|
663
|
+
@book = Book.find_by(id: params[:id])
|
630
664
|
if @book.nil?
|
631
665
|
@books = Book.all
|
632
|
-
flash[:alert] = "Your book was not found"
|
666
|
+
flash.now[:alert] = "Your book was not found"
|
633
667
|
render "index"
|
634
668
|
end
|
635
669
|
end
|
@@ -704,7 +738,7 @@ WARNING: The asset tag helpers do _not_ verify the existence of the assets at th
|
|
704
738
|
|
705
739
|
#### Linking to Feeds with the `auto_discovery_link_tag`
|
706
740
|
|
707
|
-
The `auto_discovery_link_tag` helper builds HTML that most browsers and
|
741
|
+
The `auto_discovery_link_tag` helper builds HTML that most browsers and feed readers can use to detect the presence of RSS or Atom feeds. It takes the type of the link (`:rss` or `:atom`), a hash of options that are passed through to url_for, and a hash of options for the tag:
|
708
742
|
|
709
743
|
```erb
|
710
744
|
<%= auto_discovery_link_tag(:rss, {action: "feed"},
|
@@ -869,7 +903,7 @@ You can also specify multiple videos to play by passing an array of videos to th
|
|
869
903
|
This will produce:
|
870
904
|
|
871
905
|
```erb
|
872
|
-
<video><source src="trailer.ogg" /><source src="
|
906
|
+
<video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
|
873
907
|
```
|
874
908
|
|
875
909
|
#### Linking to Audio Files with the `audio_tag`
|
@@ -1009,7 +1043,6 @@ You can also pass local variables into partials, making them even more powerful
|
|
1009
1043
|
|
1010
1044
|
```html+erb
|
1011
1045
|
<h1>New zone</h1>
|
1012
|
-
<%= error_messages_for :zone %>
|
1013
1046
|
<%= render partial: "form", locals: {zone: @zone} %>
|
1014
1047
|
```
|
1015
1048
|
|
@@ -1017,7 +1050,6 @@ You can also pass local variables into partials, making them even more powerful
|
|
1017
1050
|
|
1018
1051
|
```html+erb
|
1019
1052
|
<h1>Editing zone</h1>
|
1020
|
-
<%= error_messages_for :zone %>
|
1021
1053
|
<%= render partial: "form", locals: {zone: @zone} %>
|
1022
1054
|
```
|
1023
1055
|
|
@@ -1026,7 +1058,7 @@ You can also pass local variables into partials, making them even more powerful
|
|
1026
1058
|
```html+erb
|
1027
1059
|
<%= form_for(zone) do |f| %>
|
1028
1060
|
<p>
|
1029
|
-
<b>Zone name</b><br
|
1061
|
+
<b>Zone name</b><br>
|
1030
1062
|
<%= f.text_field :name %>
|
1031
1063
|
</p>
|
1032
1064
|
<p>
|
@@ -1122,11 +1154,11 @@ With this change, you can access an instance of the `@products` collection as th
|
|
1122
1154
|
You can also pass in arbitrary local variables to any partial you are rendering with the `locals: {}` option:
|
1123
1155
|
|
1124
1156
|
```erb
|
1125
|
-
<%= render partial: "
|
1157
|
+
<%= render partial: "product", collection: @products,
|
1126
1158
|
as: :item, locals: {title: "Products Page"} %>
|
1127
1159
|
```
|
1128
1160
|
|
1129
|
-
|
1161
|
+
In this case, the partial will have access to a local variable `title` with the value "Products Page".
|
1130
1162
|
|
1131
1163
|
TIP: Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by `_counter`. For example, if you're rendering `@products`, within the partial you can refer to `product_counter` to tell you how many times the partial has been rendered. This does not work in conjunction with the `as: :value` option.
|
1132
1164
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
Maintenance Policy for Ruby on Rails
|
2
|
+
====================================
|
3
|
+
|
4
|
+
Support of the Rails framework is divided into four groups: New features, bug
|
5
|
+
fixes, security issues, and severe security issues. They are handled as
|
6
|
+
follows, all versions in `X.Y.Z` format.
|
7
|
+
|
8
|
+
--------------------------------------------------------------------------------
|
9
|
+
|
10
|
+
Rails follows a shifted version of [semver](http://semver.org/):
|
11
|
+
|
12
|
+
**Patch `Z`**
|
13
|
+
|
14
|
+
Only bug fixes, no API changes, no new features.
|
15
|
+
Except as necessary for security fixes.
|
16
|
+
|
17
|
+
**Minor `Y`**
|
18
|
+
|
19
|
+
New features, may contain API changes (Serve as major versions of Semver).
|
20
|
+
Breaking changes are paired with deprecation notices in the previous minor
|
21
|
+
or major release.
|
22
|
+
|
23
|
+
**Major `X`**
|
24
|
+
|
25
|
+
New features, will likely contain API changes. The difference between Rails'
|
26
|
+
minor and major releases is the magnitude of breaking changes, and usually
|
27
|
+
reserved for special occasions.
|
28
|
+
|
29
|
+
New Features
|
30
|
+
------------
|
31
|
+
|
32
|
+
New features are only added to the master branch and will not be made available
|
33
|
+
in point releases.
|
34
|
+
|
35
|
+
Bug Fixes
|
36
|
+
---------
|
37
|
+
|
38
|
+
Only the latest release series will receive bug fixes. When enough bugs are
|
39
|
+
fixed and its deemed worthy to release a new gem, this is the branch it happens
|
40
|
+
from.
|
41
|
+
|
42
|
+
In special situations, where someone from the Core Team agrees to support more series,
|
43
|
+
they are included in the list of supported series.
|
44
|
+
|
45
|
+
**Currently included series:** `4.2.Z`, `4.1.Z` (Supported by Rafael França).
|
46
|
+
|
47
|
+
Security Issues
|
48
|
+
---------------
|
49
|
+
|
50
|
+
The current release series and the next most recent one will receive patches
|
51
|
+
and new versions in case of a security issue.
|
52
|
+
|
53
|
+
These releases are created by taking the last released version, applying the
|
54
|
+
security patches, and releasing. Those patches are then applied to the end of
|
55
|
+
the x-y-stable branch. For example, a theoretical 1.2.3 security release would
|
56
|
+
be built from 1.2.2, and then added to the end of 1-2-stable. This means that
|
57
|
+
security releases are easy to upgrade to if you're running the latest version
|
58
|
+
of Rails.
|
59
|
+
|
60
|
+
**Currently included series:** `4.2.Z`, `4.1.Z`.
|
61
|
+
|
62
|
+
Severe Security Issues
|
63
|
+
----------------------
|
64
|
+
|
65
|
+
For severe security issues we will provide new versions as above, and also the
|
66
|
+
last major release series will receive patches and new versions. The
|
67
|
+
classification of the security issue is judged by the core team.
|
68
|
+
|
69
|
+
**Currently included series:** `4.2.Z`, `4.1.Z`, `3.2.Z`.
|
70
|
+
|
71
|
+
Unsupported Release Series
|
72
|
+
--------------------------
|
73
|
+
|
74
|
+
When a release series is no longer supported, it's your own responsibility to
|
75
|
+
deal with bugs and security issues. We may provide backports of the fixes and
|
76
|
+
publish them to git, however there will be no new versions released. If you are
|
77
|
+
not comfortable maintaining your own versions, you should upgrade to a
|
78
|
+
supported version.
|