rails 4.2.0.beta4 → 4.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/guides/Rakefile +3 -1
- data/guides/bug_report_templates/action_controller_gem.rb +2 -2
- data/guides/bug_report_templates/action_controller_master.rb +2 -2
- data/guides/source/3_0_release_notes.md +2 -2
- data/guides/source/4_1_release_notes.md +1 -1
- data/guides/source/4_2_release_notes.md +250 -225
- data/guides/source/_welcome.html.erb +1 -1
- data/guides/source/action_controller_overview.md +6 -6
- data/guides/source/action_mailer_basics.md +26 -11
- data/guides/source/action_view_overview.md +0 -1
- data/guides/source/active_job_basics.md +29 -23
- data/guides/source/active_record_postgresql.md +2 -7
- data/guides/source/active_record_validations.md +1 -0
- data/guides/source/active_support_core_extensions.md +1 -1
- data/guides/source/active_support_instrumentation.md +5 -5
- data/guides/source/asset_pipeline.md +2 -2
- data/guides/source/association_basics.md +0 -2
- data/guides/source/command_line.md +6 -15
- data/guides/source/configuring.md +4 -4
- data/guides/source/documents.yaml +0 -1
- data/guides/source/engines.md +26 -15
- data/guides/source/form_helpers.md +10 -2
- data/guides/source/getting_started.md +9 -9
- data/guides/source/rails_on_rack.md +2 -2
- data/guides/source/ruby_on_rails_guides_guidelines.md +1 -0
- data/guides/source/security.md +1 -1
- data/guides/source/testing.md +80 -13
- data/guides/source/upgrading_ruby_on_rails.md +23 -20
- metadata +29 -229
- data/guides/output/2_2_release_notes.html +0 -724
- data/guides/output/2_3_release_notes.html +0 -870
- data/guides/output/3_0_release_notes.html +0 -773
- data/guides/output/3_1_release_notes.html +0 -740
- data/guides/output/3_2_release_notes.html +0 -797
- data/guides/output/4_0_release_notes.html +0 -523
- data/guides/output/4_1_release_notes.html +0 -806
- data/guides/output/4_2_release_notes.html +0 -728
- data/guides/output/Gemfile +0 -6
- data/guides/output/_license.html +0 -226
- data/guides/output/_welcome.html +0 -233
- data/guides/output/action_controller_overview.html +0 -1335
- data/guides/output/action_mailer_basics.html +0 -928
- data/guides/output/action_view_overview.html +0 -1509
- data/guides/output/active_job_basics.html +0 -546
- data/guides/output/active_model_basics.html +0 -438
- data/guides/output/active_record_basics.html +0 -594
- data/guides/output/active_record_callbacks.html +0 -592
- data/guides/output/active_record_migrations.html +0 -1123
- data/guides/output/active_record_postgresql.html +0 -675
- data/guides/output/active_record_querying.html +0 -1796
- data/guides/output/active_record_validations.html +0 -1301
- data/guides/output/active_support_core_extensions.html +0 -3450
- data/guides/output/active_support_instrumentation.html +0 -1121
- data/guides/output/api_documentation_guidelines.html +0 -498
- data/guides/output/asset_pipeline.html +0 -1167
- data/guides/output/association_basics.html +0 -2086
- data/guides/output/caching_with_rails.html +0 -553
- data/guides/output/command_line.html +0 -791
- data/guides/output/configuring.html +0 -1055
- data/guides/output/contributing_to_ruby_on_rails.html +0 -657
- data/guides/output/credits.html +0 -284
- data/guides/output/debugging_rails_applications.html +0 -1014
- data/guides/output/development_dependencies_install.html +0 -478
- data/guides/output/engines.html +0 -1438
- data/guides/output/form_helpers.html +0 -1074
- data/guides/output/generators.html +0 -838
- data/guides/output/getting_started.html +0 -2092
- data/guides/output/i18n.html +0 -1198
- data/guides/output/images/akshaysurve.jpg +0 -0
- data/guides/output/images/belongs_to.png +0 -0
- data/guides/output/images/book_icon.gif +0 -0
- data/guides/output/images/bullet.gif +0 -0
- data/guides/output/images/chapters_icon.gif +0 -0
- data/guides/output/images/check_bullet.gif +0 -0
- data/guides/output/images/credits_pic_blank.gif +0 -0
- data/guides/output/images/csrf.png +0 -0
- data/guides/output/images/edge_badge.png +0 -0
- data/guides/output/images/favicon.ico +0 -0
- data/guides/output/images/feature_tile.gif +0 -0
- data/guides/output/images/footer_tile.gif +0 -0
- data/guides/output/images/fxn.png +0 -0
- data/guides/output/images/getting_started/article_with_comments.png +0 -0
- data/guides/output/images/getting_started/challenge.png +0 -0
- data/guides/output/images/getting_started/confirm_dialog.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
- data/guides/output/images/getting_started/form_with_errors.png +0 -0
- data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
- data/guides/output/images/getting_started/new_article.png +0 -0
- data/guides/output/images/getting_started/new_post.png +0 -0
- data/guides/output/images/getting_started/post_with_comments.png +0 -0
- data/guides/output/images/getting_started/rails_welcome.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
- data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
- data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
- data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
- data/guides/output/images/grey_bullet.gif +0 -0
- data/guides/output/images/habtm.png +0 -0
- data/guides/output/images/has_many.png +0 -0
- data/guides/output/images/has_many_through.png +0 -0
- data/guides/output/images/has_one.png +0 -0
- data/guides/output/images/has_one_through.png +0 -0
- data/guides/output/images/header_backdrop.png +0 -0
- data/guides/output/images/header_tile.gif +0 -0
- data/guides/output/images/i18n/demo_html_safe.png +0 -0
- data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translated_en.png +0 -0
- data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translation_missing.png +0 -0
- data/guides/output/images/i18n/demo_untranslated.png +0 -0
- data/guides/output/images/icons/README +0 -5
- data/guides/output/images/icons/callouts/1.png +0 -0
- data/guides/output/images/icons/callouts/10.png +0 -0
- data/guides/output/images/icons/callouts/11.png +0 -0
- data/guides/output/images/icons/callouts/12.png +0 -0
- data/guides/output/images/icons/callouts/13.png +0 -0
- data/guides/output/images/icons/callouts/14.png +0 -0
- data/guides/output/images/icons/callouts/15.png +0 -0
- data/guides/output/images/icons/callouts/2.png +0 -0
- data/guides/output/images/icons/callouts/3.png +0 -0
- data/guides/output/images/icons/callouts/4.png +0 -0
- data/guides/output/images/icons/callouts/5.png +0 -0
- data/guides/output/images/icons/callouts/6.png +0 -0
- data/guides/output/images/icons/callouts/7.png +0 -0
- data/guides/output/images/icons/callouts/8.png +0 -0
- data/guides/output/images/icons/callouts/9.png +0 -0
- data/guides/output/images/icons/caution.png +0 -0
- data/guides/output/images/icons/example.png +0 -0
- data/guides/output/images/icons/home.png +0 -0
- data/guides/output/images/icons/important.png +0 -0
- data/guides/output/images/icons/next.png +0 -0
- data/guides/output/images/icons/note.png +0 -0
- data/guides/output/images/icons/prev.png +0 -0
- data/guides/output/images/icons/tip.png +0 -0
- data/guides/output/images/icons/up.png +0 -0
- data/guides/output/images/icons/warning.png +0 -0
- data/guides/output/images/nav_arrow.gif +0 -0
- data/guides/output/images/oscardelben.jpg +0 -0
- data/guides/output/images/polymorphic.png +0 -0
- data/guides/output/images/radar.png +0 -0
- data/guides/output/images/rails4_features.png +0 -0
- data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
- data/guides/output/images/rails_guides_logo.gif +0 -0
- data/guides/output/images/rails_logo_remix.gif +0 -0
- data/guides/output/images/session_fixation.png +0 -0
- data/guides/output/images/tab_grey.gif +0 -0
- data/guides/output/images/tab_info.gif +0 -0
- data/guides/output/images/tab_note.gif +0 -0
- data/guides/output/images/tab_red.gif +0 -0
- data/guides/output/images/tab_yellow.gif +0 -0
- data/guides/output/images/tab_yellow.png +0 -0
- data/guides/output/images/vijaydev.jpg +0 -0
- data/guides/output/index.html +0 -354
- data/guides/output/initialization.html +0 -876
- data/guides/output/javascripts/guides.js +0 -59
- data/guides/output/javascripts/jquery.min.js +0 -4
- data/guides/output/javascripts/responsive-tables.js +0 -43
- data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
- data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
- data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
- data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
- data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
- data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
- data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
- data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
- data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
- data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
- data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
- data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
- data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
- data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
- data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
- data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
- data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
- data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
- data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
- data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
- data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
- data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
- data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
- data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
- data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
- data/guides/output/javascripts/syntaxhighlighter/shCore.js +0 -17
- data/guides/output/layout.html +0 -448
- data/guides/output/layouts_and_rendering.html +0 -1541
- data/guides/output/maintenance_policy.html +0 -257
- data/guides/output/migrations.html +0 -1360
- data/guides/output/nested_model_forms.html +0 -412
- data/guides/output/plugins.html +0 -644
- data/guides/output/rails_application_templates.html +0 -450
- data/guides/output/rails_on_rack.html +0 -547
- data/guides/output/routing.html +0 -1631
- data/guides/output/ruby_on_rails_guides_guidelines.html +0 -329
- data/guides/output/security.html +0 -935
- data/guides/output/stylesheets/fixes.css +0 -16
- data/guides/output/stylesheets/kindle.css +0 -11
- data/guides/output/stylesheets/main.css +0 -713
- data/guides/output/stylesheets/print.css +0 -52
- data/guides/output/stylesheets/reset.css +0 -43
- data/guides/output/stylesheets/responsive-tables.css +0 -50
- data/guides/output/stylesheets/style.css +0 -13
- data/guides/output/stylesheets/syntaxhighlighter/shCore.css +0 -226
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
- data/guides/output/testing.html +0 -1350
- data/guides/output/upgrading_ruby_on_rails.html +0 -1135
- data/guides/output/working_with_javascript_in_rails.html +0 -587
@@ -1,450 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
7
|
-
|
8
|
-
<title>Rails Application Templates — Ruby on Rails Guides</title>
|
9
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
10
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
11
|
-
|
12
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
13
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
|
16
|
-
|
17
|
-
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
|
18
|
-
</head>
|
19
|
-
<body class="guide">
|
20
|
-
<div id="topNav">
|
21
|
-
<div class="wrapper">
|
22
|
-
<strong class="more-info-label">More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
|
23
|
-
<span class="red-button more-info-button">
|
24
|
-
More Ruby on Rails
|
25
|
-
</span>
|
26
|
-
<ul class="more-info-links s-hidden">
|
27
|
-
<li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
|
28
|
-
<li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
|
29
|
-
<li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
|
30
|
-
<li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
|
31
|
-
<li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
|
32
|
-
<li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
|
33
|
-
<li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
|
34
|
-
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
|
35
|
-
</ul>
|
36
|
-
</div>
|
37
|
-
</div>
|
38
|
-
<div id="header">
|
39
|
-
<div class="wrapper clearfix">
|
40
|
-
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
|
41
|
-
<ul class="nav">
|
42
|
-
<li><a class="nav-item" href="index.html">Home</a></li>
|
43
|
-
<li class="guides-index guides-index-large">
|
44
|
-
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guides Index</a>
|
45
|
-
<div id="guides" class="clearfix" style="display: none;">
|
46
|
-
<hr />
|
47
|
-
<dl class="L">
|
48
|
-
<dt>Start Here</dt>
|
49
|
-
<dd><a href="getting_started.html">Getting Started with Rails</a></dd>
|
50
|
-
<dt>Models</dt>
|
51
|
-
<dd><a href="active_record_basics.html">Active Record Basics</a></dd>
|
52
|
-
<dd><a href="active_record_migrations.html">Active Record Migrations</a></dd>
|
53
|
-
<dd><a href="active_record_validations.html">Active Record Validations</a></dd>
|
54
|
-
<dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd>
|
55
|
-
<dd><a href="association_basics.html">Active Record Associations</a></dd>
|
56
|
-
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
|
57
|
-
<dt>Views</dt>
|
58
|
-
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
|
59
|
-
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
|
60
|
-
<dt>Controllers</dt>
|
61
|
-
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
|
62
|
-
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
|
63
|
-
</dl>
|
64
|
-
<dl class="R">
|
65
|
-
<dt>Digging Deeper</dt>
|
66
|
-
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
|
67
|
-
<dd><a href="i18n.html">Rails Internationalization API</a></dd>
|
68
|
-
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
|
69
|
-
<dd><a href="active_job_basics.html">Active Job Basics</a></dd>
|
70
|
-
<dd><a href="security.html">Securing Rails Applications</a></dd>
|
71
|
-
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
|
72
|
-
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
|
73
|
-
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
|
74
|
-
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
|
75
|
-
<dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd>
|
76
|
-
<dt>Extending Rails</dt>
|
77
|
-
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
|
78
|
-
<dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
|
79
|
-
<dt>Contributing to Ruby on Rails</dt>
|
80
|
-
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
|
81
|
-
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
82
|
-
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
83
|
-
<dt>Maintenance Policy</dt>
|
84
|
-
<dd><a href="maintenance_policy.html">Maintenance Policy</a></dd>
|
85
|
-
<dt>Release Notes</dt>
|
86
|
-
<dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd>
|
87
|
-
<dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</a></dd>
|
88
|
-
<dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</a></dd>
|
89
|
-
<dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</a></dd>
|
90
|
-
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
|
91
|
-
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
92
|
-
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
|
93
|
-
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
|
94
|
-
</dl>
|
95
|
-
</div>
|
96
|
-
</li>
|
97
|
-
<li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li>
|
98
|
-
<li><a class="nav-item" href="credits.html">Credits</a></li>
|
99
|
-
<li class="guides-index guides-index-small">
|
100
|
-
<select class="guides-index-item nav-item">
|
101
|
-
<option value="index.html">Guides Index</option>
|
102
|
-
<optgroup label="Start Here">
|
103
|
-
<option value="getting_started.html">Getting Started with Rails</option>
|
104
|
-
</optgroup>
|
105
|
-
<optgroup label="Models">
|
106
|
-
<option value="active_record_basics.html">Active Record Basics</option>
|
107
|
-
<option value="active_record_migrations.html">Active Record Migrations</option>
|
108
|
-
<option value="active_record_validations.html">Active Record Validations</option>
|
109
|
-
<option value="active_record_callbacks.html">Active Record Callbacks</option>
|
110
|
-
<option value="association_basics.html">Active Record Associations</option>
|
111
|
-
<option value="active_record_querying.html">Active Record Query Interface</option>
|
112
|
-
</optgroup>
|
113
|
-
<optgroup label="Views">
|
114
|
-
<option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option>
|
115
|
-
<option value="form_helpers.html">Action View Form Helpers</option>
|
116
|
-
</optgroup>
|
117
|
-
<optgroup label="Controllers">
|
118
|
-
<option value="action_controller_overview.html">Action Controller Overview</option>
|
119
|
-
<option value="routing.html">Rails Routing from the Outside In</option>
|
120
|
-
</optgroup>
|
121
|
-
<optgroup label="Digging Deeper">
|
122
|
-
<option value="active_support_core_extensions.html">Active Support Core Extensions</option>
|
123
|
-
<option value="i18n.html">Rails Internationalization API</option>
|
124
|
-
<option value="action_mailer_basics.html">Action Mailer Basics</option>
|
125
|
-
<option value="active_job_basics.html">Active Job Basics</option>
|
126
|
-
<option value="security.html">Securing Rails Applications</option>
|
127
|
-
<option value="debugging_rails_applications.html">Debugging Rails Applications</option>
|
128
|
-
<option value="configuring.html">Configuring Rails Applications</option>
|
129
|
-
<option value="command_line.html">Rails Command Line Tools and Rake Tasks</option>
|
130
|
-
<option value="asset_pipeline.html">Asset Pipeline</option>
|
131
|
-
<option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option>
|
132
|
-
</optgroup>
|
133
|
-
<optgroup label="Extending Rails">
|
134
|
-
<option value="rails_on_rack.html">Rails on Rack</option>
|
135
|
-
<option value="generators.html">Creating and Customizing Rails Generators</option>
|
136
|
-
</optgroup>
|
137
|
-
<optgroup label="Contributing to Ruby on Rails">
|
138
|
-
<option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option>
|
139
|
-
<option value="api_documentation_guidelines.html">API Documentation Guidelines</option>
|
140
|
-
<option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</option>
|
141
|
-
</optgroup>
|
142
|
-
<optgroup label="Maintenance Policy">
|
143
|
-
<option value="maintenance_policy.html">Maintenance Policy</option>
|
144
|
-
</optgroup>
|
145
|
-
<optgroup label="Release Notes">
|
146
|
-
<option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option>
|
147
|
-
<option value="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</option>
|
148
|
-
<option value="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</option>
|
149
|
-
<option value="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</option>
|
150
|
-
<option value="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</option>
|
151
|
-
<option value="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</option>
|
152
|
-
<option value="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</option>
|
153
|
-
<option value="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</option>
|
154
|
-
</optgroup>
|
155
|
-
</select>
|
156
|
-
</li>
|
157
|
-
</ul>
|
158
|
-
</div>
|
159
|
-
</div>
|
160
|
-
<hr class="hide" />
|
161
|
-
|
162
|
-
<div id="feature">
|
163
|
-
<div class="wrapper">
|
164
|
-
<h2>Rails Application Templates</h2><p>Application templates are simple Ruby files containing DSL for adding gems/initializers etc. to your freshly created Rails project or an existing Rails project.</p><p>After reading this guide, you will know:</p>
|
165
|
-
<ul>
|
166
|
-
<li>How to use templates to generate/customize Rails applications.</li>
|
167
|
-
<li>How to write your own reusable application templates using the Rails template API.</li>
|
168
|
-
</ul>
|
169
|
-
|
170
|
-
|
171
|
-
<div id="subCol">
|
172
|
-
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
|
173
|
-
<ol class="chapters">
|
174
|
-
<li><a href="#usage">Usage</a></li>
|
175
|
-
<li>
|
176
|
-
<a href="#template-api">Template API</a>
|
177
|
-
|
178
|
-
<ul>
|
179
|
-
<li><a href="#gem(*args)">gem(*args)</a></li>
|
180
|
-
<li><a href="#gem_group(*names,-&block)">gem_group(*names, &block)</a></li>
|
181
|
-
<li><a href="#add_source(source,-options-=-%7B%7D)">add_source(source, options = {})</a></li>
|
182
|
-
<li><a href="#environment/application(data=nil,-options=%7B%7D,-&block)">environment/application(data=nil, options={}, &block)</a></li>
|
183
|
-
<li><a href="#vendor/lib/file/initializer(filename,-data-=-nil,-&block)">vendor/lib/file/initializer(filename, data = nil, &block)</a></li>
|
184
|
-
<li><a href="#rakefile(filename,-data-=-nil,-&block)">rakefile(filename, data = nil, &block)</a></li>
|
185
|
-
<li><a href="#generate(what,-*args)">generate(what, *args)</a></li>
|
186
|
-
<li><a href="#run(command)">run(command)</a></li>
|
187
|
-
<li><a href="#rake(command,-options-=-%7B%7D)">rake(command, options = {})</a></li>
|
188
|
-
<li><a href="#route(routing_code)">route(routing_code)</a></li>
|
189
|
-
<li><a href="#inside(dir)">inside(dir)</a></li>
|
190
|
-
<li><a href="#ask(question)">ask(question)</a></li>
|
191
|
-
<li><a href="#yes-questionmark(question)-or-no-questionmark(question)">yes?(question) or no?(question)</a></li>
|
192
|
-
<li><a href="#git(:command)">git(:command)</a></li>
|
193
|
-
<li><a href="#after_bundle(&block)">after_bundle(&block)</a></li>
|
194
|
-
</ul>
|
195
|
-
</li>
|
196
|
-
<li><a href="#advanced-usage">Advanced Usage</a></li>
|
197
|
-
</ol>
|
198
|
-
|
199
|
-
</div>
|
200
|
-
|
201
|
-
</div>
|
202
|
-
</div>
|
203
|
-
|
204
|
-
<div id="container">
|
205
|
-
<div class="wrapper">
|
206
|
-
<div id="mainCol">
|
207
|
-
<h3 id="usage">1 Usage</h3><p>To apply a template, you need to provide the Rails generator with the location of the template you wish to apply using the -m option. This can either be a path to a file or a URL.</p><div class="code_container">
|
208
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
209
|
-
$ rails new blog -m ~/template.rb
|
210
|
-
$ rails new blog -m http://example.com/template.rb
|
211
|
-
|
212
|
-
</pre>
|
213
|
-
</div>
|
214
|
-
<p>You can use the rake task <code>rails:template</code> to apply templates to an existing Rails application. The location of the template needs to be passed in to an environment variable named LOCATION. Again, this can either be path to a file or a URL.</p><div class="code_container">
|
215
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
216
|
-
$ bin/rake rails:template LOCATION=~/template.rb
|
217
|
-
$ bin/rake rails:template LOCATION=http://example.com/template.rb
|
218
|
-
|
219
|
-
</pre>
|
220
|
-
</div>
|
221
|
-
<h3 id="template-api">2 Template API</h3><p>The Rails templates API is easy to understand. Here's an example of a typical Rails template:</p><div class="code_container">
|
222
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
223
|
-
# template.rb
|
224
|
-
generate(:scaffold, "person name:string")
|
225
|
-
route "root to: 'people#index'"
|
226
|
-
rake("db:migrate")
|
227
|
-
|
228
|
-
after_bundle do
|
229
|
-
git :init
|
230
|
-
git add: "."
|
231
|
-
git commit: %Q{ -m 'Initial commit' }
|
232
|
-
end
|
233
|
-
|
234
|
-
</pre>
|
235
|
-
</div>
|
236
|
-
<p>The following sections outline the primary methods provided by the API:</p><h4 id="gem(*args)">2.1 gem(*args)</h4><p>Adds a <code>gem</code> entry for the supplied gem to the generated application's <code>Gemfile</code>.</p><p>For example, if your application depends on the gems <code>bj</code> and <code>nokogiri</code>:</p><div class="code_container">
|
237
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
238
|
-
gem "bj"
|
239
|
-
gem "nokogiri"
|
240
|
-
|
241
|
-
</pre>
|
242
|
-
</div>
|
243
|
-
<p>Please note that this will NOT install the gems for you and you will have to run <code>bundle install</code> to do that.</p><div class="code_container">
|
244
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
245
|
-
bundle install
|
246
|
-
|
247
|
-
</pre>
|
248
|
-
</div>
|
249
|
-
<h4 id="gem_group(*names,-&block)">2.2 gem_group(*names, &block)</h4><p>Wraps gem entries inside a group.</p><p>For example, if you want to load <code>rspec-rails</code> only in the <code>development</code> and <code>test</code> groups:</p><div class="code_container">
|
250
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
251
|
-
gem_group :development, :test do
|
252
|
-
gem "rspec-rails"
|
253
|
-
end
|
254
|
-
|
255
|
-
</pre>
|
256
|
-
</div>
|
257
|
-
<h4 id="add_source(source,-options-=-{})">2.3 add_source(source, options = {})</h4><p>Adds the given source to the generated application's <code>Gemfile</code>.</p><p>For example, if you need to source a gem from <code>"http://code.whytheluckystiff.net"</code>:</p><div class="code_container">
|
258
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
259
|
-
add_source "http://code.whytheluckystiff.net"
|
260
|
-
|
261
|
-
</pre>
|
262
|
-
</div>
|
263
|
-
<h4 id="environment/application(data=nil,-options={},-&block)">2.4 environment/application(data=nil, options={}, &block)</h4><p>Adds a line inside the <code>Application</code> class for <code>config/application.rb</code>.</p><p>If <code>options[:env]</code> is specified, the line is appended to the corresponding file in <code>config/environments</code>.</p><div class="code_container">
|
264
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
265
|
-
environment 'config.action_mailer.default_url_options = {host: "http://yourwebsite.example.com"}', env: 'production'
|
266
|
-
|
267
|
-
</pre>
|
268
|
-
</div>
|
269
|
-
<p>A block can be used in place of the <code>data</code> argument.</p><h4 id="vendor/lib/file/initializer(filename,-data-=-nil,-&block)">2.5 vendor/lib/file/initializer(filename, data = nil, &block)</h4><p>Adds an initializer to the generated application's <code>config/initializers</code> directory.</p><p>Let's say you like using <code>Object#not_nil?</code> and <code>Object#not_blank?</code>:</p><div class="code_container">
|
270
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
271
|
-
initializer 'bloatlol.rb', <<-CODE
|
272
|
-
class Object
|
273
|
-
def not_nil?
|
274
|
-
!nil?
|
275
|
-
end
|
276
|
-
|
277
|
-
def not_blank?
|
278
|
-
!blank?
|
279
|
-
end
|
280
|
-
end
|
281
|
-
CODE
|
282
|
-
|
283
|
-
</pre>
|
284
|
-
</div>
|
285
|
-
<p>Similarly, <code>lib()</code> creates a file in the <code>lib/</code> directory and <code>vendor()</code> creates a file in the <code>vendor/</code> directory.</p><p>There is even <code>file()</code>, which accepts a relative path from <code>Rails.root</code> and creates all the directories/files needed:</p><div class="code_container">
|
286
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
287
|
-
file 'app/components/foo.rb', <<-CODE
|
288
|
-
class Foo
|
289
|
-
end
|
290
|
-
CODE
|
291
|
-
|
292
|
-
</pre>
|
293
|
-
</div>
|
294
|
-
<p>That'll create the <code>app/components</code> directory and put <code>foo.rb</code> in there.</p><h4 id="rakefile(filename,-data-=-nil,-&block)">2.6 rakefile(filename, data = nil, &block)</h4><p>Creates a new rake file under <code>lib/tasks</code> with the supplied tasks:</p><div class="code_container">
|
295
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
296
|
-
rakefile("bootstrap.rake") do
|
297
|
-
<<-TASK
|
298
|
-
namespace :boot do
|
299
|
-
task :strap do
|
300
|
-
puts "i like boots!"
|
301
|
-
end
|
302
|
-
end
|
303
|
-
TASK
|
304
|
-
end
|
305
|
-
|
306
|
-
</pre>
|
307
|
-
</div>
|
308
|
-
<p>The above creates <code>lib/tasks/bootstrap.rake</code> with a <code>boot:strap</code> rake task.</p><h4 id="generate(what,-*args)">2.7 generate(what, *args)</h4><p>Runs the supplied rails generator with given arguments.</p><div class="code_container">
|
309
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
310
|
-
generate(:scaffold, "person", "name:string", "address:text", "age:number")
|
311
|
-
|
312
|
-
</pre>
|
313
|
-
</div>
|
314
|
-
<h4 id="run(command)">2.8 run(command)</h4><p>Executes an arbitrary command. Just like the backticks. Let's say you want to remove the <code>README.rdoc</code> file:</p><div class="code_container">
|
315
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
316
|
-
run "rm README.rdoc"
|
317
|
-
|
318
|
-
</pre>
|
319
|
-
</div>
|
320
|
-
<h4 id="rake(command,-options-=-{})">2.9 rake(command, options = {})</h4><p>Runs the supplied rake tasks in the Rails application. Let's say you want to migrate the database:</p><div class="code_container">
|
321
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
322
|
-
rake "db:migrate"
|
323
|
-
|
324
|
-
</pre>
|
325
|
-
</div>
|
326
|
-
<p>You can also run rake tasks with a different Rails environment:</p><div class="code_container">
|
327
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
328
|
-
rake "db:migrate", env: 'production'
|
329
|
-
|
330
|
-
</pre>
|
331
|
-
</div>
|
332
|
-
<h4 id="route(routing_code)">2.10 route(routing_code)</h4><p>Adds a routing entry to the <code>config/routes.rb</code> file. In the steps above, we generated a person scaffold and also removed <code>README.rdoc</code>. Now, to make <code>PeopleController#index</code> the default page for the application:</p><div class="code_container">
|
333
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
334
|
-
route "root to: 'person#index'"
|
335
|
-
|
336
|
-
</pre>
|
337
|
-
</div>
|
338
|
-
<h4 id="inside(dir)">2.11 inside(dir)</h4><p>Enables you to run a command from the given directory. For example, if you have a copy of edge rails that you wish to symlink from your new apps, you can do this:</p><div class="code_container">
|
339
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
340
|
-
inside('vendor') do
|
341
|
-
run "ln -s ~/commit-rails/rails rails"
|
342
|
-
end
|
343
|
-
|
344
|
-
</pre>
|
345
|
-
</div>
|
346
|
-
<h4 id="ask(question)">2.12 ask(question)</h4><p><code>ask()</code> gives you a chance to get some feedback from the user and use it in your templates. Let's say you want your user to name the new shiny library you're adding:</p><div class="code_container">
|
347
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
348
|
-
lib_name = ask("What do you want to call the shiny library ?")
|
349
|
-
lib_name << ".rb" unless lib_name.index(".rb")
|
350
|
-
|
351
|
-
lib lib_name, <<-CODE
|
352
|
-
class Shiny
|
353
|
-
end
|
354
|
-
CODE
|
355
|
-
|
356
|
-
</pre>
|
357
|
-
</div>
|
358
|
-
<h4 id="yes-questionmark(question)-or-no-questionmark(question)">2.13 yes?(question) or no?(question)</h4><p>These methods let you ask questions from templates and decide the flow based on the user's answer. Let's say you want to freeze rails only if the user wants to:</p><div class="code_container">
|
359
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
360
|
-
rake("rails:freeze:gems") if yes?("Freeze rails gems?")
|
361
|
-
# no?(question) acts just the opposite.
|
362
|
-
|
363
|
-
</pre>
|
364
|
-
</div>
|
365
|
-
<h4 id="git(:command)">2.14 git(:command)</h4><p>Rails templates let you run any git command:</p><div class="code_container">
|
366
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
367
|
-
git :init
|
368
|
-
git add: "."
|
369
|
-
git commit: "-a -m 'Initial commit'"
|
370
|
-
|
371
|
-
</pre>
|
372
|
-
</div>
|
373
|
-
<h4 id="after_bundle(&block)">2.15 after_bundle(&block)</h4><p>Registers a callback to be executed after the gems are bundled and binstubs
|
374
|
-
are generated. Useful for all generated files to version control:</p><div class="code_container">
|
375
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
376
|
-
after_bundle do
|
377
|
-
git :init
|
378
|
-
git add: '.'
|
379
|
-
git commit: "-a -m 'Initial commit'"
|
380
|
-
end
|
381
|
-
|
382
|
-
</pre>
|
383
|
-
</div>
|
384
|
-
<p>The callbacks gets executed even if <code>--skip-bundle</code> and/or <code>--skip-spring</code> has
|
385
|
-
been passed.</p><h3 id="advanced-usage">3 Advanced Usage</h3><p>The application template is evaluated in the context of a
|
386
|
-
<code>Rails::Generators::AppGenerator</code> instance. It uses the <code>apply</code> action
|
387
|
-
provided by
|
388
|
-
<a href="https://github.com/erikhuda/thor/blob/master/lib/thor/actions.rb#L207">Thor</a>.
|
389
|
-
This means you can extend and change the instance to match your needs.</p><p>For example by overwriting the <code>source_paths</code> method to contain the
|
390
|
-
location of your template. Now methods like <code>copy_file</code> will accept
|
391
|
-
relative paths to your template's location.</p><div class="code_container">
|
392
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
393
|
-
def source_paths
|
394
|
-
[File.expand_path(File.dirname(__FILE__))]
|
395
|
-
end
|
396
|
-
|
397
|
-
</pre>
|
398
|
-
</div>
|
399
|
-
|
400
|
-
|
401
|
-
<h3>Feedback</h3>
|
402
|
-
<p>
|
403
|
-
You're encouraged to help improve the quality of this guide.
|
404
|
-
</p>
|
405
|
-
<p>
|
406
|
-
Please contribute if you see any typos or factual errors.
|
407
|
-
To get started, you can read our <a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section.
|
408
|
-
</p>
|
409
|
-
<p>
|
410
|
-
You may also find incomplete content, or stuff that is not up to date.
|
411
|
-
Please do add any missing documentation for master. Make sure to check
|
412
|
-
<a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
|
413
|
-
if the issues are already fixed or not on the master branch.
|
414
|
-
Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
|
415
|
-
for style and conventions.
|
416
|
-
</p>
|
417
|
-
<p>
|
418
|
-
If for whatever reason you spot something to fix but cannot patch it yourself, please
|
419
|
-
<a href="https://github.com/rails/rails/issues">open an issue</a>.
|
420
|
-
</p>
|
421
|
-
<p>And last but not least, any kind of discussion regarding Ruby on Rails
|
422
|
-
documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
|
423
|
-
</p>
|
424
|
-
</div>
|
425
|
-
</div>
|
426
|
-
</div>
|
427
|
-
|
428
|
-
<hr class="hide" />
|
429
|
-
<div id="footer">
|
430
|
-
<div class="wrapper">
|
431
|
-
<p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p>
|
432
|
-
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
433
|
-
|
434
|
-
</div>
|
435
|
-
</div>
|
436
|
-
|
437
|
-
<script type="text/javascript" src="javascripts/jquery.min.js"></script>
|
438
|
-
<script type="text/javascript" src="javascripts/responsive-tables.js"></script>
|
439
|
-
<script type="text/javascript" src="javascripts/guides.js"></script>
|
440
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
441
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
442
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
443
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
444
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
445
|
-
<script type="text/javascript">
|
446
|
-
SyntaxHighlighter.all();
|
447
|
-
$(guidesIndex.bind);
|
448
|
-
</script>
|
449
|
-
</body>
|
450
|
-
</html>
|
@@ -1,547 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
7
|
-
|
8
|
-
<title>Rails on Rack — Ruby on Rails Guides</title>
|
9
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
10
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
11
|
-
|
12
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
13
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
|
16
|
-
|
17
|
-
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
|
18
|
-
</head>
|
19
|
-
<body class="guide">
|
20
|
-
<div id="topNav">
|
21
|
-
<div class="wrapper">
|
22
|
-
<strong class="more-info-label">More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
|
23
|
-
<span class="red-button more-info-button">
|
24
|
-
More Ruby on Rails
|
25
|
-
</span>
|
26
|
-
<ul class="more-info-links s-hidden">
|
27
|
-
<li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
|
28
|
-
<li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
|
29
|
-
<li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
|
30
|
-
<li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
|
31
|
-
<li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
|
32
|
-
<li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
|
33
|
-
<li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
|
34
|
-
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
|
35
|
-
</ul>
|
36
|
-
</div>
|
37
|
-
</div>
|
38
|
-
<div id="header">
|
39
|
-
<div class="wrapper clearfix">
|
40
|
-
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
|
41
|
-
<ul class="nav">
|
42
|
-
<li><a class="nav-item" href="index.html">Home</a></li>
|
43
|
-
<li class="guides-index guides-index-large">
|
44
|
-
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guides Index</a>
|
45
|
-
<div id="guides" class="clearfix" style="display: none;">
|
46
|
-
<hr />
|
47
|
-
<dl class="L">
|
48
|
-
<dt>Start Here</dt>
|
49
|
-
<dd><a href="getting_started.html">Getting Started with Rails</a></dd>
|
50
|
-
<dt>Models</dt>
|
51
|
-
<dd><a href="active_record_basics.html">Active Record Basics</a></dd>
|
52
|
-
<dd><a href="active_record_migrations.html">Active Record Migrations</a></dd>
|
53
|
-
<dd><a href="active_record_validations.html">Active Record Validations</a></dd>
|
54
|
-
<dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd>
|
55
|
-
<dd><a href="association_basics.html">Active Record Associations</a></dd>
|
56
|
-
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
|
57
|
-
<dt>Views</dt>
|
58
|
-
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
|
59
|
-
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
|
60
|
-
<dt>Controllers</dt>
|
61
|
-
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
|
62
|
-
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
|
63
|
-
</dl>
|
64
|
-
<dl class="R">
|
65
|
-
<dt>Digging Deeper</dt>
|
66
|
-
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
|
67
|
-
<dd><a href="i18n.html">Rails Internationalization API</a></dd>
|
68
|
-
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
|
69
|
-
<dd><a href="active_job_basics.html">Active Job Basics</a></dd>
|
70
|
-
<dd><a href="security.html">Securing Rails Applications</a></dd>
|
71
|
-
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
|
72
|
-
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
|
73
|
-
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
|
74
|
-
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
|
75
|
-
<dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd>
|
76
|
-
<dt>Extending Rails</dt>
|
77
|
-
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
|
78
|
-
<dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
|
79
|
-
<dt>Contributing to Ruby on Rails</dt>
|
80
|
-
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
|
81
|
-
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
82
|
-
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
83
|
-
<dt>Maintenance Policy</dt>
|
84
|
-
<dd><a href="maintenance_policy.html">Maintenance Policy</a></dd>
|
85
|
-
<dt>Release Notes</dt>
|
86
|
-
<dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd>
|
87
|
-
<dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</a></dd>
|
88
|
-
<dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</a></dd>
|
89
|
-
<dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</a></dd>
|
90
|
-
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
|
91
|
-
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
92
|
-
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
|
93
|
-
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
|
94
|
-
</dl>
|
95
|
-
</div>
|
96
|
-
</li>
|
97
|
-
<li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li>
|
98
|
-
<li><a class="nav-item" href="credits.html">Credits</a></li>
|
99
|
-
<li class="guides-index guides-index-small">
|
100
|
-
<select class="guides-index-item nav-item">
|
101
|
-
<option value="index.html">Guides Index</option>
|
102
|
-
<optgroup label="Start Here">
|
103
|
-
<option value="getting_started.html">Getting Started with Rails</option>
|
104
|
-
</optgroup>
|
105
|
-
<optgroup label="Models">
|
106
|
-
<option value="active_record_basics.html">Active Record Basics</option>
|
107
|
-
<option value="active_record_migrations.html">Active Record Migrations</option>
|
108
|
-
<option value="active_record_validations.html">Active Record Validations</option>
|
109
|
-
<option value="active_record_callbacks.html">Active Record Callbacks</option>
|
110
|
-
<option value="association_basics.html">Active Record Associations</option>
|
111
|
-
<option value="active_record_querying.html">Active Record Query Interface</option>
|
112
|
-
</optgroup>
|
113
|
-
<optgroup label="Views">
|
114
|
-
<option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option>
|
115
|
-
<option value="form_helpers.html">Action View Form Helpers</option>
|
116
|
-
</optgroup>
|
117
|
-
<optgroup label="Controllers">
|
118
|
-
<option value="action_controller_overview.html">Action Controller Overview</option>
|
119
|
-
<option value="routing.html">Rails Routing from the Outside In</option>
|
120
|
-
</optgroup>
|
121
|
-
<optgroup label="Digging Deeper">
|
122
|
-
<option value="active_support_core_extensions.html">Active Support Core Extensions</option>
|
123
|
-
<option value="i18n.html">Rails Internationalization API</option>
|
124
|
-
<option value="action_mailer_basics.html">Action Mailer Basics</option>
|
125
|
-
<option value="active_job_basics.html">Active Job Basics</option>
|
126
|
-
<option value="security.html">Securing Rails Applications</option>
|
127
|
-
<option value="debugging_rails_applications.html">Debugging Rails Applications</option>
|
128
|
-
<option value="configuring.html">Configuring Rails Applications</option>
|
129
|
-
<option value="command_line.html">Rails Command Line Tools and Rake Tasks</option>
|
130
|
-
<option value="asset_pipeline.html">Asset Pipeline</option>
|
131
|
-
<option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option>
|
132
|
-
</optgroup>
|
133
|
-
<optgroup label="Extending Rails">
|
134
|
-
<option value="rails_on_rack.html">Rails on Rack</option>
|
135
|
-
<option value="generators.html">Creating and Customizing Rails Generators</option>
|
136
|
-
</optgroup>
|
137
|
-
<optgroup label="Contributing to Ruby on Rails">
|
138
|
-
<option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option>
|
139
|
-
<option value="api_documentation_guidelines.html">API Documentation Guidelines</option>
|
140
|
-
<option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</option>
|
141
|
-
</optgroup>
|
142
|
-
<optgroup label="Maintenance Policy">
|
143
|
-
<option value="maintenance_policy.html">Maintenance Policy</option>
|
144
|
-
</optgroup>
|
145
|
-
<optgroup label="Release Notes">
|
146
|
-
<option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option>
|
147
|
-
<option value="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</option>
|
148
|
-
<option value="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</option>
|
149
|
-
<option value="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</option>
|
150
|
-
<option value="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</option>
|
151
|
-
<option value="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</option>
|
152
|
-
<option value="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</option>
|
153
|
-
<option value="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</option>
|
154
|
-
</optgroup>
|
155
|
-
</select>
|
156
|
-
</li>
|
157
|
-
</ul>
|
158
|
-
</div>
|
159
|
-
</div>
|
160
|
-
<hr class="hide" />
|
161
|
-
|
162
|
-
<div id="feature">
|
163
|
-
<div class="wrapper">
|
164
|
-
<h2>Rails on Rack</h2><p>This guide covers Rails integration with Rack and interfacing with other Rack components.</p><p>After reading this guide, you will know:</p>
|
165
|
-
<ul>
|
166
|
-
<li>How to use Rack Middlewares in your Rails applications.</li>
|
167
|
-
<li>Action Pack's internal Middleware stack.</li>
|
168
|
-
<li>How to define a custom Middleware stack.</li>
|
169
|
-
</ul>
|
170
|
-
|
171
|
-
|
172
|
-
<div id="subCol">
|
173
|
-
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
|
174
|
-
<ol class="chapters">
|
175
|
-
<li><a href="#introduction-to-rack">Introduction to Rack</a></li>
|
176
|
-
<li>
|
177
|
-
<a href="#rails-on-rack">Rails on Rack</a>
|
178
|
-
|
179
|
-
<ul>
|
180
|
-
<li><a href="#rails-application's-rack-object">Rails Application's Rack Object</a></li>
|
181
|
-
<li><a href="#rails-server"><code>rails server</code></a></li>
|
182
|
-
<li><a href="#rackup"><code>rackup</code></a></li>
|
183
|
-
</ul>
|
184
|
-
</li>
|
185
|
-
<li>
|
186
|
-
<a href="#action-dispatcher-middleware-stack">Action Dispatcher Middleware Stack</a>
|
187
|
-
|
188
|
-
<ul>
|
189
|
-
<li><a href="#inspecting-middleware-stack">Inspecting Middleware Stack</a></li>
|
190
|
-
<li><a href="#configuring-middleware-stack">Configuring Middleware Stack</a></li>
|
191
|
-
<li><a href="#internal-middleware-stack">Internal Middleware Stack</a></li>
|
192
|
-
</ul>
|
193
|
-
</li>
|
194
|
-
<li>
|
195
|
-
<a href="#resources">Resources</a>
|
196
|
-
|
197
|
-
<ul>
|
198
|
-
<li><a href="#learning-rack">Learning Rack</a></li>
|
199
|
-
<li><a href="#understanding-middlewares">Understanding Middlewares</a></li>
|
200
|
-
</ul>
|
201
|
-
</li>
|
202
|
-
</ol>
|
203
|
-
|
204
|
-
</div>
|
205
|
-
|
206
|
-
</div>
|
207
|
-
</div>
|
208
|
-
|
209
|
-
<div id="container">
|
210
|
-
<div class="wrapper">
|
211
|
-
<div id="mainCol">
|
212
|
-
<div class="warning"><p>This guide assumes a working knowledge of Rack protocol and Rack concepts such as middlewares, url maps and <code>Rack::Builder</code>.</p></div><h3 id="introduction-to-rack">1 Introduction to Rack</h3><p>Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.</p>
|
213
|
-
<ul>
|
214
|
-
<li><a href="http://rack.github.io/">Rack API Documentation</a></li>
|
215
|
-
</ul>
|
216
|
-
<p>Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack's basics, you should check out the <a href="#resources">Resources</a> section below.</p><h3 id="rails-on-rack">2 Rails on Rack</h3><h4 id="rails-application's-rack-object">2.1 Rails Application's Rack Object</h4><p><code>Rails.application</code> is the primary Rack application object of a Rails
|
217
|
-
application. Any Rack compliant web server should be using
|
218
|
-
<code>Rails.application</code> object to serve a Rails application.</p><h4 id="rails-server">2.2 <code>rails server</code>
|
219
|
-
</h4><p><code>rails server</code> does the basic job of creating a <code>Rack::Server</code> object and starting the webserver.</p><p>Here's how <code>rails server</code> creates an instance of <code>Rack::Server</code></p><div class="code_container">
|
220
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
221
|
-
Rails::Server.new.tap do |server|
|
222
|
-
require APP_PATH
|
223
|
-
Dir.chdir(Rails.application.root)
|
224
|
-
server.start
|
225
|
-
end
|
226
|
-
|
227
|
-
</pre>
|
228
|
-
</div>
|
229
|
-
<p>The <code>Rails::Server</code> inherits from <code>Rack::Server</code> and calls the <code>Rack::Server#start</code> method this way:</p><div class="code_container">
|
230
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
231
|
-
class Server < ::Rack::Server
|
232
|
-
def start
|
233
|
-
...
|
234
|
-
super
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
</pre>
|
239
|
-
</div>
|
240
|
-
<p>Here's how it loads the middlewares:</p><div class="code_container">
|
241
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
242
|
-
def middleware
|
243
|
-
middlewares = []
|
244
|
-
middlewares << [Rails::Rack::Debugger] if options[:debugger]
|
245
|
-
middlewares << [::Rack::ContentLength]
|
246
|
-
Hash.new(middlewares)
|
247
|
-
end
|
248
|
-
|
249
|
-
</pre>
|
250
|
-
</div>
|
251
|
-
<p><code>Rails::Rack::Debugger</code> is primarily useful only in the development environment. The following table explains the usage of the loaded middlewares:</p>
|
252
|
-
<table>
|
253
|
-
<thead>
|
254
|
-
<tr>
|
255
|
-
<th>Middleware</th>
|
256
|
-
<th>Purpose</th>
|
257
|
-
</tr>
|
258
|
-
</thead>
|
259
|
-
<tbody>
|
260
|
-
<tr>
|
261
|
-
<td><code>Rails::Rack::Debugger</code></td>
|
262
|
-
<td>Starts Debugger</td>
|
263
|
-
</tr>
|
264
|
-
<tr>
|
265
|
-
<td><code>Rack::ContentLength</code></td>
|
266
|
-
<td>Counts the number of bytes in the response and set the HTTP Content-Length header</td>
|
267
|
-
</tr>
|
268
|
-
</tbody>
|
269
|
-
</table>
|
270
|
-
<h4 id="rackup">2.3 <code>rackup</code>
|
271
|
-
</h4><p>To use <code>rackup</code> instead of Rails' <code>rails server</code>, you can put the following inside <code>config.ru</code> of your Rails application's root directory:</p><div class="code_container">
|
272
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
273
|
-
# Rails.root/config.ru
|
274
|
-
require ::File.expand_path('../config/environment', __FILE__)
|
275
|
-
|
276
|
-
use Rails::Rack::Debugger
|
277
|
-
use Rack::ContentLength
|
278
|
-
run Rails.application
|
279
|
-
|
280
|
-
</pre>
|
281
|
-
</div>
|
282
|
-
<p>And start the server:</p><div class="code_container">
|
283
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
284
|
-
$ rackup config.ru
|
285
|
-
|
286
|
-
</pre>
|
287
|
-
</div>
|
288
|
-
<p>To find out more about different <code>rackup</code> options:</p><div class="code_container">
|
289
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
290
|
-
$ rackup --help
|
291
|
-
|
292
|
-
</pre>
|
293
|
-
</div>
|
294
|
-
<h3 id="action-dispatcher-middleware-stack">3 Action Dispatcher Middleware Stack</h3><p>Many of Action Dispatcher's internal components are implemented as Rack middlewares. <code>Rails::Application</code> uses <code>ActionDispatch::MiddlewareStack</code> to combine various internal and external middlewares to form a complete Rails Rack application.</p><div class="note"><p><code>ActionDispatch::MiddlewareStack</code> is Rails equivalent of <code>Rack::Builder</code>, but built for better flexibility and more features to meet Rails' requirements.</p></div><h4 id="inspecting-middleware-stack">3.1 Inspecting Middleware Stack</h4><p>Rails has a handy rake task for inspecting the middleware stack in use:</p><div class="code_container">
|
295
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
296
|
-
$ bin/rake middleware
|
297
|
-
|
298
|
-
</pre>
|
299
|
-
</div>
|
300
|
-
<p>For a freshly generated Rails application, this might produce something like:</p><div class="code_container">
|
301
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
302
|
-
use Rack::Sendfile
|
303
|
-
use ActionDispatch::Static
|
304
|
-
use Rack::Lock
|
305
|
-
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x000000029a0838>
|
306
|
-
use Rack::Runtime
|
307
|
-
use Rack::MethodOverride
|
308
|
-
use ActionDispatch::RequestId
|
309
|
-
use Rails::Rack::Logger
|
310
|
-
use ActionDispatch::ShowExceptions
|
311
|
-
use ActionDispatch::DebugExceptions
|
312
|
-
use ActionDispatch::RemoteIp
|
313
|
-
use ActionDispatch::Reloader
|
314
|
-
use ActionDispatch::Callbacks
|
315
|
-
use ActiveRecord::Migration::CheckPending
|
316
|
-
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
317
|
-
use ActiveRecord::QueryCache
|
318
|
-
use ActionDispatch::Cookies
|
319
|
-
use ActionDispatch::Session::CookieStore
|
320
|
-
use ActionDispatch::Flash
|
321
|
-
use ActionDispatch::ParamsParser
|
322
|
-
use Rack::Head
|
323
|
-
use Rack::ConditionalGet
|
324
|
-
use Rack::ETag
|
325
|
-
run Rails.application.routes
|
326
|
-
|
327
|
-
</pre>
|
328
|
-
</div>
|
329
|
-
<p>The default middlewares shown here (and some others) are each summarized in the <a href="#internal-middleware-stack">Internal Middlewares</a> section, below.</p><h4 id="configuring-middleware-stack">3.2 Configuring Middleware Stack</h4><p>Rails provides a simple configuration interface <code>config.middleware</code> for adding, removing and modifying the middlewares in the middleware stack via <code>application.rb</code> or the environment specific configuration file <code>environments/<environment>.rb</code>.</p><h5 id="adding-a-middleware">3.2.1 Adding a Middleware</h5><p>You can add a new middleware to the middleware stack using any of the following methods:</p>
|
330
|
-
<ul>
|
331
|
-
<li><p><code>config.middleware.use(new_middleware, args)</code> - Adds the new middleware at the bottom of the middleware stack.</p></li>
|
332
|
-
<li><p><code>config.middleware.insert_before(existing_middleware, new_middleware, args)</code> - Adds the new middleware before the specified existing middleware in the middleware stack.</p></li>
|
333
|
-
<li><p><code>config.middleware.insert_after(existing_middleware, new_middleware, args)</code> - Adds the new middleware after the specified existing middleware in the middleware stack.</p></li>
|
334
|
-
</ul>
|
335
|
-
<div class="code_container">
|
336
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
337
|
-
# config/application.rb
|
338
|
-
|
339
|
-
# Push Rack::BounceFavicon at the bottom
|
340
|
-
config.middleware.use Rack::BounceFavicon
|
341
|
-
|
342
|
-
# Add Lifo::Cache after ActiveRecord::QueryCache.
|
343
|
-
# Pass { page_cache: false } argument to Lifo::Cache.
|
344
|
-
config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, page_cache: false
|
345
|
-
|
346
|
-
</pre>
|
347
|
-
</div>
|
348
|
-
<h5 id="swapping-a-middleware">3.2.2 Swapping a Middleware</h5><p>You can swap an existing middleware in the middleware stack using <code>config.middleware.swap</code>.</p><div class="code_container">
|
349
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
350
|
-
# config/application.rb
|
351
|
-
|
352
|
-
# Replace ActionDispatch::ShowExceptions with Lifo::ShowExceptions
|
353
|
-
config.middleware.swap ActionDispatch::ShowExceptions, Lifo::ShowExceptions
|
354
|
-
|
355
|
-
</pre>
|
356
|
-
</div>
|
357
|
-
<h5 id="deleting-a-middleware">3.2.3 Deleting a Middleware</h5><p>Add the following lines to your application configuration:</p><div class="code_container">
|
358
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
359
|
-
# config/application.rb
|
360
|
-
config.middleware.delete "Rack::Lock"
|
361
|
-
|
362
|
-
</pre>
|
363
|
-
</div>
|
364
|
-
<p>And now if you inspect the middleware stack, you'll find that <code>Rack::Lock</code> is
|
365
|
-
not a part of it.</p><div class="code_container">
|
366
|
-
<pre class="brush: plain; gutter: false; toolbar: false">
|
367
|
-
$ bin/rake middleware
|
368
|
-
(in /Users/lifo/Rails/blog)
|
369
|
-
use ActionDispatch::Static
|
370
|
-
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000001c304c8>
|
371
|
-
use Rack::Runtime
|
372
|
-
...
|
373
|
-
run Rails.application.routes
|
374
|
-
|
375
|
-
</pre>
|
376
|
-
</div>
|
377
|
-
<p>If you want to remove session related middleware, do the following:</p><div class="code_container">
|
378
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
379
|
-
# config/application.rb
|
380
|
-
config.middleware.delete "ActionDispatch::Cookies"
|
381
|
-
config.middleware.delete "ActionDispatch::Session::CookieStore"
|
382
|
-
config.middleware.delete "ActionDispatch::Flash"
|
383
|
-
|
384
|
-
</pre>
|
385
|
-
</div>
|
386
|
-
<p>And to remove browser related middleware,</p><div class="code_container">
|
387
|
-
<pre class="brush: ruby; gutter: false; toolbar: false">
|
388
|
-
# config/application.rb
|
389
|
-
config.middleware.delete "Rack::MethodOverride"
|
390
|
-
|
391
|
-
</pre>
|
392
|
-
</div>
|
393
|
-
<h4 id="internal-middleware-stack">3.3 Internal Middleware Stack</h4><p>Much of Action Controller's functionality is implemented as Middlewares. The following list explains the purpose of each of them:</p><p><strong><code>Rack::Sendfile</code></strong></p>
|
394
|
-
<ul>
|
395
|
-
<li>Sets server specific X-Sendfile header. Configure this via <code>config.action_dispatch.x_sendfile_header</code> option.</li>
|
396
|
-
</ul>
|
397
|
-
<p><strong><code>ActionDispatch::Static</code></strong></p>
|
398
|
-
<ul>
|
399
|
-
<li>Used to serve static assets. Disabled if <code>config.serve_static_assets</code> is <code>false</code>.</li>
|
400
|
-
</ul>
|
401
|
-
<p><strong><code>Rack::Lock</code></strong></p>
|
402
|
-
<ul>
|
403
|
-
<li>Sets <code>env["rack.multithread"]</code> flag to <code>false</code> and wraps the application within a Mutex.</li>
|
404
|
-
</ul>
|
405
|
-
<p><strong><code>ActiveSupport::Cache::Strategy::LocalCache::Middleware</code></strong></p>
|
406
|
-
<ul>
|
407
|
-
<li>Used for memory caching. This cache is not thread safe.</li>
|
408
|
-
</ul>
|
409
|
-
<p><strong><code>Rack::Runtime</code></strong></p>
|
410
|
-
<ul>
|
411
|
-
<li>Sets an X-Runtime header, containing the time (in seconds) taken to execute the request.</li>
|
412
|
-
</ul>
|
413
|
-
<p><strong><code>Rack::MethodOverride</code></strong></p>
|
414
|
-
<ul>
|
415
|
-
<li>Allows the method to be overridden if <code>params[:_method]</code> is set. This is the middleware which supports the PUT and DELETE HTTP method types.</li>
|
416
|
-
</ul>
|
417
|
-
<p><strong><code>ActionDispatch::RequestId</code></strong></p>
|
418
|
-
<ul>
|
419
|
-
<li>Makes a unique <code>X-Request-Id</code> header available to the response and enables the <code>ActionDispatch::Request#uuid</code> method.</li>
|
420
|
-
</ul>
|
421
|
-
<p><strong><code>Rails::Rack::Logger</code></strong></p>
|
422
|
-
<ul>
|
423
|
-
<li>Notifies the logs that the request has began. After request is complete, flushes all the logs.</li>
|
424
|
-
</ul>
|
425
|
-
<p><strong><code>ActionDispatch::ShowExceptions</code></strong></p>
|
426
|
-
<ul>
|
427
|
-
<li>Rescues any exception returned by the application and calls an exceptions app that will wrap it in a format for the end user.</li>
|
428
|
-
</ul>
|
429
|
-
<p><strong><code>ActionDispatch::DebugExceptions</code></strong></p>
|
430
|
-
<ul>
|
431
|
-
<li>Responsible for logging exceptions and showing a debugging page in case the request is local.</li>
|
432
|
-
</ul>
|
433
|
-
<p><strong><code>ActionDispatch::RemoteIp</code></strong></p>
|
434
|
-
<ul>
|
435
|
-
<li>Checks for IP spoofing attacks.</li>
|
436
|
-
</ul>
|
437
|
-
<p><strong><code>ActionDispatch::Reloader</code></strong></p>
|
438
|
-
<ul>
|
439
|
-
<li>Provides prepare and cleanup callbacks, intended to assist with code reloading during development.</li>
|
440
|
-
</ul>
|
441
|
-
<p><strong><code>ActionDispatch::Callbacks</code></strong></p>
|
442
|
-
<ul>
|
443
|
-
<li>Runs the prepare callbacks before serving the request.</li>
|
444
|
-
</ul>
|
445
|
-
<p><strong><code>ActiveRecord::Migration::CheckPending</code></strong></p>
|
446
|
-
<ul>
|
447
|
-
<li>Checks pending migrations and raises <code>ActiveRecord::PendingMigrationError</code> if any migrations are pending.</li>
|
448
|
-
</ul>
|
449
|
-
<p><strong><code>ActiveRecord::ConnectionAdapters::ConnectionManagement</code></strong></p>
|
450
|
-
<ul>
|
451
|
-
<li>Cleans active connections after each request, unless the <code>rack.test</code> key in the request environment is set to <code>true</code>.</li>
|
452
|
-
</ul>
|
453
|
-
<p><strong><code>ActiveRecord::QueryCache</code></strong></p>
|
454
|
-
<ul>
|
455
|
-
<li>Enables the Active Record query cache.</li>
|
456
|
-
</ul>
|
457
|
-
<p><strong><code>ActionDispatch::Cookies</code></strong></p>
|
458
|
-
<ul>
|
459
|
-
<li>Sets cookies for the request.</li>
|
460
|
-
</ul>
|
461
|
-
<p><strong><code>ActionDispatch::Session::CookieStore</code></strong></p>
|
462
|
-
<ul>
|
463
|
-
<li>Responsible for storing the session in cookies.</li>
|
464
|
-
</ul>
|
465
|
-
<p><strong><code>ActionDispatch::Flash</code></strong></p>
|
466
|
-
<ul>
|
467
|
-
<li>Sets up the flash keys. Only available if <code>config.action_controller.session_store</code> is set to a value.</li>
|
468
|
-
</ul>
|
469
|
-
<p><strong><code>ActionDispatch::ParamsParser</code></strong></p>
|
470
|
-
<ul>
|
471
|
-
<li>Parses out parameters from the request into <code>params</code>.</li>
|
472
|
-
</ul>
|
473
|
-
<p><strong><code>ActionDispatch::Head</code></strong></p>
|
474
|
-
<ul>
|
475
|
-
<li>Converts HEAD requests to <code>GET</code> requests and serves them as so.</li>
|
476
|
-
</ul>
|
477
|
-
<p><strong><code>Rack::ConditionalGet</code></strong></p>
|
478
|
-
<ul>
|
479
|
-
<li>Adds support for "Conditional <code>GET</code>" so that server responds with nothing if page wasn't changed.</li>
|
480
|
-
</ul>
|
481
|
-
<p><strong><code>Rack::ETag</code></strong></p>
|
482
|
-
<ul>
|
483
|
-
<li>Adds ETag header on all String bodies. ETags are used to validate cache.</li>
|
484
|
-
</ul>
|
485
|
-
<div class="info"><p>It's possible to use any of the above middlewares in your custom Rack stack.</p></div><h3 id="resources">4 Resources</h3><h4 id="learning-rack">4.1 Learning Rack</h4>
|
486
|
-
<ul>
|
487
|
-
<li><a href="http://rack.github.io">Official Rack Website</a></li>
|
488
|
-
<li><a href="http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html">Introducing Rack</a></li>
|
489
|
-
<li><a href="http://m.onkey.org/ruby-on-rack-1-hello-rack">Ruby on Rack #1 - Hello Rack!</a></li>
|
490
|
-
<li><a href="http://m.onkey.org/ruby-on-rack-2-the-builder">Ruby on Rack #2 - The Builder</a></li>
|
491
|
-
</ul>
|
492
|
-
<h4 id="understanding-middlewares">4.2 Understanding Middlewares</h4>
|
493
|
-
<ul>
|
494
|
-
<li><a href="http://railscasts.com/episodes/151-rack-middleware">Railscast on Rack Middlewares</a></li>
|
495
|
-
</ul>
|
496
|
-
|
497
|
-
|
498
|
-
<h3>Feedback</h3>
|
499
|
-
<p>
|
500
|
-
You're encouraged to help improve the quality of this guide.
|
501
|
-
</p>
|
502
|
-
<p>
|
503
|
-
Please contribute if you see any typos or factual errors.
|
504
|
-
To get started, you can read our <a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section.
|
505
|
-
</p>
|
506
|
-
<p>
|
507
|
-
You may also find incomplete content, or stuff that is not up to date.
|
508
|
-
Please do add any missing documentation for master. Make sure to check
|
509
|
-
<a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
|
510
|
-
if the issues are already fixed or not on the master branch.
|
511
|
-
Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
|
512
|
-
for style and conventions.
|
513
|
-
</p>
|
514
|
-
<p>
|
515
|
-
If for whatever reason you spot something to fix but cannot patch it yourself, please
|
516
|
-
<a href="https://github.com/rails/rails/issues">open an issue</a>.
|
517
|
-
</p>
|
518
|
-
<p>And last but not least, any kind of discussion regarding Ruby on Rails
|
519
|
-
documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
|
520
|
-
</p>
|
521
|
-
</div>
|
522
|
-
</div>
|
523
|
-
</div>
|
524
|
-
|
525
|
-
<hr class="hide" />
|
526
|
-
<div id="footer">
|
527
|
-
<div class="wrapper">
|
528
|
-
<p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p>
|
529
|
-
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
530
|
-
|
531
|
-
</div>
|
532
|
-
</div>
|
533
|
-
|
534
|
-
<script type="text/javascript" src="javascripts/jquery.min.js"></script>
|
535
|
-
<script type="text/javascript" src="javascripts/responsive-tables.js"></script>
|
536
|
-
<script type="text/javascript" src="javascripts/guides.js"></script>
|
537
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
538
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
539
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
540
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
541
|
-
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
542
|
-
<script type="text/javascript">
|
543
|
-
SyntaxHighlighter.all();
|
544
|
-
$(guidesIndex.bind);
|
545
|
-
</script>
|
546
|
-
</body>
|
547
|
-
</html>
|