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.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/guides/Rakefile +3 -1
  3. data/guides/bug_report_templates/action_controller_gem.rb +2 -2
  4. data/guides/bug_report_templates/action_controller_master.rb +2 -2
  5. data/guides/source/3_0_release_notes.md +2 -2
  6. data/guides/source/4_1_release_notes.md +1 -1
  7. data/guides/source/4_2_release_notes.md +250 -225
  8. data/guides/source/_welcome.html.erb +1 -1
  9. data/guides/source/action_controller_overview.md +6 -6
  10. data/guides/source/action_mailer_basics.md +26 -11
  11. data/guides/source/action_view_overview.md +0 -1
  12. data/guides/source/active_job_basics.md +29 -23
  13. data/guides/source/active_record_postgresql.md +2 -7
  14. data/guides/source/active_record_validations.md +1 -0
  15. data/guides/source/active_support_core_extensions.md +1 -1
  16. data/guides/source/active_support_instrumentation.md +5 -5
  17. data/guides/source/asset_pipeline.md +2 -2
  18. data/guides/source/association_basics.md +0 -2
  19. data/guides/source/command_line.md +6 -15
  20. data/guides/source/configuring.md +4 -4
  21. data/guides/source/documents.yaml +0 -1
  22. data/guides/source/engines.md +26 -15
  23. data/guides/source/form_helpers.md +10 -2
  24. data/guides/source/getting_started.md +9 -9
  25. data/guides/source/rails_on_rack.md +2 -2
  26. data/guides/source/ruby_on_rails_guides_guidelines.md +1 -0
  27. data/guides/source/security.md +1 -1
  28. data/guides/source/testing.md +80 -13
  29. data/guides/source/upgrading_ruby_on_rails.md +23 -20
  30. metadata +29 -229
  31. data/guides/output/2_2_release_notes.html +0 -724
  32. data/guides/output/2_3_release_notes.html +0 -870
  33. data/guides/output/3_0_release_notes.html +0 -773
  34. data/guides/output/3_1_release_notes.html +0 -740
  35. data/guides/output/3_2_release_notes.html +0 -797
  36. data/guides/output/4_0_release_notes.html +0 -523
  37. data/guides/output/4_1_release_notes.html +0 -806
  38. data/guides/output/4_2_release_notes.html +0 -728
  39. data/guides/output/Gemfile +0 -6
  40. data/guides/output/_license.html +0 -226
  41. data/guides/output/_welcome.html +0 -233
  42. data/guides/output/action_controller_overview.html +0 -1335
  43. data/guides/output/action_mailer_basics.html +0 -928
  44. data/guides/output/action_view_overview.html +0 -1509
  45. data/guides/output/active_job_basics.html +0 -546
  46. data/guides/output/active_model_basics.html +0 -438
  47. data/guides/output/active_record_basics.html +0 -594
  48. data/guides/output/active_record_callbacks.html +0 -592
  49. data/guides/output/active_record_migrations.html +0 -1123
  50. data/guides/output/active_record_postgresql.html +0 -675
  51. data/guides/output/active_record_querying.html +0 -1796
  52. data/guides/output/active_record_validations.html +0 -1301
  53. data/guides/output/active_support_core_extensions.html +0 -3450
  54. data/guides/output/active_support_instrumentation.html +0 -1121
  55. data/guides/output/api_documentation_guidelines.html +0 -498
  56. data/guides/output/asset_pipeline.html +0 -1167
  57. data/guides/output/association_basics.html +0 -2086
  58. data/guides/output/caching_with_rails.html +0 -553
  59. data/guides/output/command_line.html +0 -791
  60. data/guides/output/configuring.html +0 -1055
  61. data/guides/output/contributing_to_ruby_on_rails.html +0 -657
  62. data/guides/output/credits.html +0 -284
  63. data/guides/output/debugging_rails_applications.html +0 -1014
  64. data/guides/output/development_dependencies_install.html +0 -478
  65. data/guides/output/engines.html +0 -1438
  66. data/guides/output/form_helpers.html +0 -1074
  67. data/guides/output/generators.html +0 -838
  68. data/guides/output/getting_started.html +0 -2092
  69. data/guides/output/i18n.html +0 -1198
  70. data/guides/output/images/akshaysurve.jpg +0 -0
  71. data/guides/output/images/belongs_to.png +0 -0
  72. data/guides/output/images/book_icon.gif +0 -0
  73. data/guides/output/images/bullet.gif +0 -0
  74. data/guides/output/images/chapters_icon.gif +0 -0
  75. data/guides/output/images/check_bullet.gif +0 -0
  76. data/guides/output/images/credits_pic_blank.gif +0 -0
  77. data/guides/output/images/csrf.png +0 -0
  78. data/guides/output/images/edge_badge.png +0 -0
  79. data/guides/output/images/favicon.ico +0 -0
  80. data/guides/output/images/feature_tile.gif +0 -0
  81. data/guides/output/images/footer_tile.gif +0 -0
  82. data/guides/output/images/fxn.png +0 -0
  83. data/guides/output/images/getting_started/article_with_comments.png +0 -0
  84. data/guides/output/images/getting_started/challenge.png +0 -0
  85. data/guides/output/images/getting_started/confirm_dialog.png +0 -0
  86. data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  87. data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  88. data/guides/output/images/getting_started/form_with_errors.png +0 -0
  89. data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
  90. data/guides/output/images/getting_started/new_article.png +0 -0
  91. data/guides/output/images/getting_started/new_post.png +0 -0
  92. data/guides/output/images/getting_started/post_with_comments.png +0 -0
  93. data/guides/output/images/getting_started/rails_welcome.png +0 -0
  94. data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
  95. data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
  96. data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
  97. data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
  98. data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
  99. data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
  100. data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
  101. data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
  102. data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
  103. data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
  104. data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
  105. data/guides/output/images/grey_bullet.gif +0 -0
  106. data/guides/output/images/habtm.png +0 -0
  107. data/guides/output/images/has_many.png +0 -0
  108. data/guides/output/images/has_many_through.png +0 -0
  109. data/guides/output/images/has_one.png +0 -0
  110. data/guides/output/images/has_one_through.png +0 -0
  111. data/guides/output/images/header_backdrop.png +0 -0
  112. data/guides/output/images/header_tile.gif +0 -0
  113. data/guides/output/images/i18n/demo_html_safe.png +0 -0
  114. data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
  115. data/guides/output/images/i18n/demo_translated_en.png +0 -0
  116. data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
  117. data/guides/output/images/i18n/demo_translation_missing.png +0 -0
  118. data/guides/output/images/i18n/demo_untranslated.png +0 -0
  119. data/guides/output/images/icons/README +0 -5
  120. data/guides/output/images/icons/callouts/1.png +0 -0
  121. data/guides/output/images/icons/callouts/10.png +0 -0
  122. data/guides/output/images/icons/callouts/11.png +0 -0
  123. data/guides/output/images/icons/callouts/12.png +0 -0
  124. data/guides/output/images/icons/callouts/13.png +0 -0
  125. data/guides/output/images/icons/callouts/14.png +0 -0
  126. data/guides/output/images/icons/callouts/15.png +0 -0
  127. data/guides/output/images/icons/callouts/2.png +0 -0
  128. data/guides/output/images/icons/callouts/3.png +0 -0
  129. data/guides/output/images/icons/callouts/4.png +0 -0
  130. data/guides/output/images/icons/callouts/5.png +0 -0
  131. data/guides/output/images/icons/callouts/6.png +0 -0
  132. data/guides/output/images/icons/callouts/7.png +0 -0
  133. data/guides/output/images/icons/callouts/8.png +0 -0
  134. data/guides/output/images/icons/callouts/9.png +0 -0
  135. data/guides/output/images/icons/caution.png +0 -0
  136. data/guides/output/images/icons/example.png +0 -0
  137. data/guides/output/images/icons/home.png +0 -0
  138. data/guides/output/images/icons/important.png +0 -0
  139. data/guides/output/images/icons/next.png +0 -0
  140. data/guides/output/images/icons/note.png +0 -0
  141. data/guides/output/images/icons/prev.png +0 -0
  142. data/guides/output/images/icons/tip.png +0 -0
  143. data/guides/output/images/icons/up.png +0 -0
  144. data/guides/output/images/icons/warning.png +0 -0
  145. data/guides/output/images/nav_arrow.gif +0 -0
  146. data/guides/output/images/oscardelben.jpg +0 -0
  147. data/guides/output/images/polymorphic.png +0 -0
  148. data/guides/output/images/radar.png +0 -0
  149. data/guides/output/images/rails4_features.png +0 -0
  150. data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
  151. data/guides/output/images/rails_guides_logo.gif +0 -0
  152. data/guides/output/images/rails_logo_remix.gif +0 -0
  153. data/guides/output/images/session_fixation.png +0 -0
  154. data/guides/output/images/tab_grey.gif +0 -0
  155. data/guides/output/images/tab_info.gif +0 -0
  156. data/guides/output/images/tab_note.gif +0 -0
  157. data/guides/output/images/tab_red.gif +0 -0
  158. data/guides/output/images/tab_yellow.gif +0 -0
  159. data/guides/output/images/tab_yellow.png +0 -0
  160. data/guides/output/images/vijaydev.jpg +0 -0
  161. data/guides/output/index.html +0 -354
  162. data/guides/output/initialization.html +0 -876
  163. data/guides/output/javascripts/guides.js +0 -59
  164. data/guides/output/javascripts/jquery.min.js +0 -4
  165. data/guides/output/javascripts/responsive-tables.js +0 -43
  166. data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  167. data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  168. data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  169. data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  170. data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  171. data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  172. data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  173. data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  174. data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  175. data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  176. data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  177. data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  178. data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  179. data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  180. data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  181. data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  182. data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  183. data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  184. data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  185. data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  186. data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  187. data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  188. data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  189. data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  190. data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  191. data/guides/output/javascripts/syntaxhighlighter/shCore.js +0 -17
  192. data/guides/output/layout.html +0 -448
  193. data/guides/output/layouts_and_rendering.html +0 -1541
  194. data/guides/output/maintenance_policy.html +0 -257
  195. data/guides/output/migrations.html +0 -1360
  196. data/guides/output/nested_model_forms.html +0 -412
  197. data/guides/output/plugins.html +0 -644
  198. data/guides/output/rails_application_templates.html +0 -450
  199. data/guides/output/rails_on_rack.html +0 -547
  200. data/guides/output/routing.html +0 -1631
  201. data/guides/output/ruby_on_rails_guides_guidelines.html +0 -329
  202. data/guides/output/security.html +0 -935
  203. data/guides/output/stylesheets/fixes.css +0 -16
  204. data/guides/output/stylesheets/kindle.css +0 -11
  205. data/guides/output/stylesheets/main.css +0 -713
  206. data/guides/output/stylesheets/print.css +0 -52
  207. data/guides/output/stylesheets/reset.css +0 -43
  208. data/guides/output/stylesheets/responsive-tables.css +0 -50
  209. data/guides/output/stylesheets/style.css +0 -13
  210. data/guides/output/stylesheets/syntaxhighlighter/shCore.css +0 -226
  211. data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  212. data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  213. data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  214. data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  215. data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  216. data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  217. data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  218. data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  219. data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  220. data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  221. data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  222. data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  223. data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  224. data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  225. data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  226. data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  227. data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  228. data/guides/output/testing.html +0 -1350
  229. data/guides/output/upgrading_ruby_on_rails.html +0 -1135
  230. data/guides/output/working_with_javascript_in_rails.html +0 -587
@@ -1,791 +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>The Rails Command Line — 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>The Rails Command Line</h2><p>After reading this guide, you will know:</p>
165
- <ul>
166
- <li>How to create a Rails application.</li>
167
- <li>How to generate models, controllers, database migrations, and unit tests.</li>
168
- <li>How to start a development server.</li>
169
- <li>How to experiment with objects through an interactive shell.</li>
170
- </ul>
171
-
172
-
173
- <div id="subCol">
174
- <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
175
- <ol class="chapters">
176
- <li>
177
- <a href="#command-line-basics">Command Line Basics</a>
178
-
179
- <ul>
180
- <li><a href="#rails-new"><code>rails new</code></a></li>
181
- <li><a href="#rails-server"><code>rails server</code></a></li>
182
- <li><a href="#rails-generate"><code>rails generate</code></a></li>
183
- <li><a href="#rails-console"><code>rails console</code></a></li>
184
- <li><a href="#rails-dbconsole"><code>rails dbconsole</code></a></li>
185
- <li><a href="#rails-runner"><code>rails runner</code></a></li>
186
- <li><a href="#rails-destroy"><code>rails destroy</code></a></li>
187
- </ul>
188
- </li>
189
- <li>
190
- <a href="#rake">Rake</a>
191
-
192
- <ul>
193
- <li><a href="#about"><code>about</code></a></li>
194
- <li><a href="#assets"><code>assets</code></a></li>
195
- <li><a href="#db"><code>db</code></a></li>
196
- <li><a href="#doc"><code>doc</code></a></li>
197
- <li><a href="#notes"><code>notes</code></a></li>
198
- <li><a href="#routes"><code>routes</code></a></li>
199
- <li><a href="#test"><code>test</code></a></li>
200
- <li><a href="#tmp"><code>tmp</code></a></li>
201
- <li><a href="#miscellaneous">Miscellaneous</a></li>
202
- <li><a href="#custom-rake-tasks">Custom Rake Tasks</a></li>
203
- </ul>
204
- </li>
205
- <li>
206
- <a href="#the-rails-advanced-command-line">The Rails Advanced Command Line</a>
207
-
208
- <ul>
209
- <li><a href="#rails-with-databases-and-scm">Rails with Databases and SCM</a></li>
210
- </ul>
211
- </li>
212
- </ol>
213
-
214
- </div>
215
-
216
- </div>
217
- </div>
218
-
219
- <div id="container">
220
- <div class="wrapper">
221
- <div id="mainCol">
222
- <div class="note"><p>This tutorial assumes you have basic Rails knowledge from reading the <a href="getting_started.html">Getting Started with Rails Guide</a>.</p></div><h3 id="command-line-basics">1 Command Line Basics</h3><p>There are a few commands that are absolutely critical to your everyday usage of Rails. In the order of how much you'll probably use them are:</p>
223
- <ul>
224
- <li><code>rails console</code></li>
225
- <li><code>rails server</code></li>
226
- <li><code>rake</code></li>
227
- <li><code>rails generate</code></li>
228
- <li><code>rails dbconsole</code></li>
229
- <li><code>rails new app_name</code></li>
230
- </ul>
231
- <p>All commands can run with <code>-h or --help</code> to list more information.</p><p>Let's create a simple Rails application to step through each of these commands in context.</p><h4 id="rails-new">1.1 <code>rails new</code>
232
- </h4><p>The first thing we'll want to do is create a new Rails application by running the <code>rails new</code> command after installing Rails.</p><div class="info"><p>You can install the rails gem by typing <code>gem install rails</code>, if you don't have it already.</p></div><div class="code_container">
233
- <pre class="brush: plain; gutter: false; toolbar: false">
234
- $ rails new commandsapp
235
- create
236
- create README.rdoc
237
- create Rakefile
238
- create config.ru
239
- create .gitignore
240
- create Gemfile
241
- create app
242
- ...
243
- create tmp/cache
244
- ...
245
- run bundle install
246
-
247
- </pre>
248
- </div>
249
- <p>Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You've got the entire Rails directory structure now with all the code you need to run our simple application right out of the box.</p><h4 id="rails-server">1.2 <code>rails server</code>
250
- </h4><p>The <code>rails server</code> command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to access your application through a web browser.</p><p>With no further work, <code>rails server</code> will run our new shiny Rails app:</p><div class="code_container">
251
- <pre class="brush: plain; gutter: false; toolbar: false">
252
- $ cd commandsapp
253
- $ bin/rails server
254
- =&gt; Booting WEBrick
255
- =&gt; Rails 4.2.0 application starting in development on http://0.0.0.0:3000
256
- =&gt; Call with -d to detach
257
- =&gt; Ctrl-C to shutdown server
258
- [2013-08-07 02:00:01] INFO WEBrick 1.3.1
259
- [2013-08-07 02:00:01] INFO ruby 2.0.0 (2013-06-27) [x86_64-darwin11.2.0]
260
- [2013-08-07 02:00:01] INFO WEBrick::HTTPServer#start: pid=69680 port=3000
261
-
262
- </pre>
263
- </div>
264
- <p>With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open <a href="http://localhost:3000">http://localhost:3000</a>, you will see a basic Rails app running.</p><div class="info"><p>You can also use the alias "s" to start the server: <code>rails s</code>.</p></div><p>The server can be run on a different port using the <code>-p</code> option. The default development environment can be changed using <code>-e</code>.</p><div class="code_container">
265
- <pre class="brush: plain; gutter: false; toolbar: false">
266
- $ bin/rails server -e production -p 4000
267
-
268
- </pre>
269
- </div>
270
- <p>The <code>-b</code> option binds Rails to the specified IP, by default it is 0.0.0.0. You can run a server as a daemon by passing a <code>-d</code> option.</p><h4 id="rails-generate">1.3 <code>rails generate</code>
271
- </h4><p>The <code>rails generate</code> command uses templates to create a whole lot of things. Running <code>rails generate</code> by itself gives a list of available generators:</p><div class="info"><p>You can also use the alias "g" to invoke the generator command: <code>rails g</code>.</p></div><div class="code_container">
272
- <pre class="brush: plain; gutter: false; toolbar: false">
273
- $ bin/rails generate
274
- Usage: rails generate GENERATOR [args] [options]
275
-
276
- ...
277
- ...
278
-
279
- Please choose a generator below.
280
-
281
- Rails:
282
- assets
283
- controller
284
- generator
285
- ...
286
- ...
287
-
288
- </pre>
289
- </div>
290
- <div class="note"><p>You can install more generators through generator gems, portions of plugins you'll undoubtedly install, and you can even create your own!</p></div><p>Using generators will save you a large amount of time by writing <strong>boilerplate code</strong>, code that is necessary for the app to work.</p><p>Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator:</p><div class="info"><p>All Rails console utilities have help text. As with most *nix utilities, you can try adding <code>--help</code> or <code>-h</code> to the end, for example <code>rails server --help</code>.</p></div><div class="code_container">
291
- <pre class="brush: plain; gutter: false; toolbar: false">
292
- $ bin/rails generate controller
293
- Usage: rails generate controller NAME [action action] [options]
294
-
295
- ...
296
- ...
297
-
298
- Description:
299
- ...
300
-
301
- To create a controller within a module, specify the controller name as a path like 'parent_module/controller_name'.
302
-
303
- ...
304
-
305
- Example:
306
- `rails generate controller CreditCards open debit credit close`
307
-
308
- Credit card controller with URLs like /credit_cards/debit.
309
- Controller: app/controllers/credit_card_controller.rb
310
- Test: test/controllers/credit_cards_controller_test.rb
311
- Views: app/views/credit_cards/debit.html.erb [...]
312
- Helper: app/helpers/credit_cards_helper.rb
313
-
314
- </pre>
315
- </div>
316
- <p>The controller generator is expecting parameters in the form of <code>generate controller ControllerName action1 action2</code>. Let's make a <code>Greetings</code> controller with an action of <strong>hello</strong>, which will say something nice to us.</p><div class="code_container">
317
- <pre class="brush: plain; gutter: false; toolbar: false">
318
- $ bin/rails generate controller Greetings hello
319
- create app/controllers/greetings_controller.rb
320
- route get "greetings/hello"
321
- invoke erb
322
- create app/views/greetings
323
- create app/views/greetings/hello.html.erb
324
- invoke test_unit
325
- create test/controllers/greetings_controller_test.rb
326
- invoke helper
327
- create app/helpers/greetings_helper.rb
328
- invoke assets
329
- invoke coffee
330
- create app/assets/javascripts/greetings.js.coffee
331
- invoke scss
332
- create app/assets/stylesheets/greetings.css.scss
333
-
334
- </pre>
335
- </div>
336
- <p>What all did this generate? It made sure a bunch of directories were in our application, and created a controller file, a view file, a functional test file, a helper for the view, a JavaScript file and a stylesheet file.</p><p>Check out the controller and modify it a little (in <code>app/controllers/greetings_controller.rb</code>):</p><div class="code_container">
337
- <pre class="brush: ruby; gutter: false; toolbar: false">
338
- class GreetingsController &lt; ApplicationController
339
- def hello
340
- @message = "Hello, how are you today?"
341
- end
342
- end
343
-
344
- </pre>
345
- </div>
346
- <p>Then the view, to display our message (in <code>app/views/greetings/hello.html.erb</code>):</p><div class="code_container">
347
- <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
348
- &lt;h1&gt;A Greeting for You!&lt;/h1&gt;
349
- &lt;p&gt;&lt;%= @message %&gt;&lt;/p&gt;
350
-
351
- </pre>
352
- </div>
353
- <p>Fire up your server using <code>rails server</code>.</p><div class="code_container">
354
- <pre class="brush: plain; gutter: false; toolbar: false">
355
- $ bin/rails server
356
- =&gt; Booting WEBrick...
357
-
358
- </pre>
359
- </div>
360
- <p>The URL will be <a href="http://localhost:3000/greetings/hello">http://localhost:3000/greetings/hello</a>.</p><div class="info"><p>With a normal, plain-old Rails application, your URLs will generally follow the pattern of http://(host)/(controller)/(action), and a URL like http://(host)/(controller) will hit the <strong>index</strong> action of that controller.</p></div><p>Rails comes with a generator for data models too.</p><div class="code_container">
361
- <pre class="brush: plain; gutter: false; toolbar: false">
362
- $ bin/rails generate model
363
- Usage:
364
- rails generate model NAME [field[:type][:index] field[:type][:index]] [options]
365
-
366
- ...
367
-
368
- Active Record options:
369
- [--migration] # Indicates when to generate migration
370
- # Default: true
371
-
372
- ...
373
-
374
- Description:
375
- Create rails files for model generator.
376
-
377
- </pre>
378
- </div>
379
- <div class="note"><p>For a list of available field types, refer to the <a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column">API documentation</a> for the column method for the <code>TableDefinition</code> class.</p></div><p>But instead of generating a model directly (which we'll be doing later), let's set up a scaffold. A <strong>scaffold</strong> in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.</p><p>We will set up a simple resource called "HighScore" that will keep track of our highest score on video games we play.</p><div class="code_container">
380
- <pre class="brush: plain; gutter: false; toolbar: false">
381
- $ bin/rails generate scaffold HighScore game:string score:integer
382
- invoke active_record
383
- create db/migrate/20130717151933_create_high_scores.rb
384
- create app/models/high_score.rb
385
- invoke test_unit
386
- create test/models/high_score_test.rb
387
- create test/fixtures/high_scores.yml
388
- invoke resource_route
389
- route resources :high_scores
390
- invoke scaffold_controller
391
- create app/controllers/high_scores_controller.rb
392
- invoke erb
393
- create app/views/high_scores
394
- create app/views/high_scores/index.html.erb
395
- create app/views/high_scores/edit.html.erb
396
- create app/views/high_scores/show.html.erb
397
- create app/views/high_scores/new.html.erb
398
- create app/views/high_scores/_form.html.erb
399
- invoke test_unit
400
- create test/controllers/high_scores_controller_test.rb
401
- invoke helper
402
- create app/helpers/high_scores_helper.rb
403
- invoke jbuilder
404
- create app/views/high_scores/index.json.jbuilder
405
- create app/views/high_scores/show.json.jbuilder
406
- invoke assets
407
- invoke coffee
408
- create app/assets/javascripts/high_scores.js.coffee
409
- invoke scss
410
- create app/assets/stylesheets/high_scores.css.scss
411
- invoke scss
412
- identical app/assets/stylesheets/scaffolds.css.scss
413
-
414
- </pre>
415
- </div>
416
- <p>The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the <code>high_scores</code> table and fields), takes care of the route for the <strong>resource</strong>, and new tests for everything.</p><p>The migration requires that we <strong>migrate</strong>, that is, run some Ruby code (living in that <code>20130717151933_create_high_scores.rb</code>) to modify the schema of our database. Which database? The SQLite3 database that Rails will create for you when we run the <code>rake db:migrate</code> command. We'll talk more about Rake in-depth in a little while.</p><div class="code_container">
417
- <pre class="brush: plain; gutter: false; toolbar: false">
418
- $ bin/rake db:migrate
419
- == CreateHighScores: migrating ===============================================
420
- -- create_table(:high_scores)
421
- -&gt; 0.0017s
422
- == CreateHighScores: migrated (0.0019s) ======================================
423
-
424
- </pre>
425
- </div>
426
- <div class="info"><p>Let's talk about unit tests. Unit tests are code that tests and makes assertions about code. In unit testing, we take a little part of code, say a method of a model, and test its inputs and outputs. Unit tests are your friend. The sooner you make peace with the fact that your quality of life will drastically increase when you unit test your code, the better. Seriously. We'll make one in a moment.</p></div><p>Let's see the interface Rails created for us.</p><div class="code_container">
427
- <pre class="brush: plain; gutter: false; toolbar: false">
428
- $ bin/rails server
429
-
430
- </pre>
431
- </div>
432
- <p>Go to your browser and open <a href="http://localhost:3000/high_scores">http://localhost:3000/high_scores</a>, now we can create new high scores (55,160 on Space Invaders!)</p><h4 id="rails-console">1.4 <code>rails console</code>
433
- </h4><p>The <code>console</code> command lets you interact with your Rails application from the command line. On the underside, <code>rails console</code> uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.</p><div class="info"><p>You can also use the alias "c" to invoke the console: <code>rails c</code>.</p></div><p>You can specify the environment in which the <code>console</code> command should operate.</p><div class="code_container">
434
- <pre class="brush: plain; gutter: false; toolbar: false">
435
- $ bin/rails console staging
436
-
437
- </pre>
438
- </div>
439
- <p>If you wish to test out some code without changing any data, you can do that by invoking <code>rails console --sandbox</code>.</p><div class="code_container">
440
- <pre class="brush: plain; gutter: false; toolbar: false">
441
- $ bin/rails console --sandbox
442
- Loading development environment in sandbox (Rails 4.2.0)
443
- Any modifications you make will be rolled back on exit
444
- irb(main):001:0&gt;
445
-
446
- </pre>
447
- </div>
448
- <h5 id="the-app-and-helper-objects">1.4.1 The app and helper objects</h5><p>Inside the <code>rails console</code> you have access to the <code>app</code> and <code>helper</code> instances.</p><p>With the <code>app</code> method you can access url and path helpers, as well as do requests.</p><div class="code_container">
449
- <pre class="brush: plain; gutter: false; toolbar: false">
450
- &gt;&gt; app.root_path
451
- =&gt; "/"
452
-
453
- &gt;&gt; app.get _
454
- Started GET "/" for 127.0.0.1 at 2014-06-19 10:41:57 -0300
455
- ...
456
-
457
- </pre>
458
- </div>
459
- <p>With the <code>helper</code> method it is possible to access Rails and your application's helpers.</p><div class="code_container">
460
- <pre class="brush: plain; gutter: false; toolbar: false">
461
- &gt;&gt; helper.time_ago_in_words 30.days.ago
462
- =&gt; "about 1 month"
463
-
464
- &gt;&gt; helper.my_custom_helper
465
- =&gt; "my custom helper"
466
-
467
- </pre>
468
- </div>
469
- <h4 id="rails-dbconsole">1.5 <code>rails dbconsole</code>
470
- </h4><p><code>rails dbconsole</code> figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3.</p><div class="info"><p>You can also use the alias "db" to invoke the dbconsole: <code>rails db</code>.</p></div><h4 id="rails-runner">1.6 <code>rails runner</code>
471
- </h4><p><code>runner</code> runs Ruby code in the context of Rails non-interactively. For instance:</p><div class="code_container">
472
- <pre class="brush: plain; gutter: false; toolbar: false">
473
- $ bin/rails runner "Model.long_running_method"
474
-
475
- </pre>
476
- </div>
477
- <div class="info"><p>You can also use the alias "r" to invoke the runner: <code>rails r</code>.</p></div><p>You can specify the environment in which the <code>runner</code> command should operate using the <code>-e</code> switch.</p><div class="code_container">
478
- <pre class="brush: plain; gutter: false; toolbar: false">
479
- $ bin/rails runner -e staging "Model.long_running_method"
480
-
481
- </pre>
482
- </div>
483
- <h4 id="rails-destroy">1.7 <code>rails destroy</code>
484
- </h4><p>Think of <code>destroy</code> as the opposite of <code>generate</code>. It'll figure out what generate did, and undo it.</p><div class="info"><p>You can also use the alias "d" to invoke the destroy command: <code>rails d</code>.</p></div><div class="code_container">
485
- <pre class="brush: plain; gutter: false; toolbar: false">
486
- $ bin/rails generate model Oops
487
- invoke active_record
488
- create db/migrate/20120528062523_create_oops.rb
489
- create app/models/oops.rb
490
- invoke test_unit
491
- create test/models/oops_test.rb
492
- create test/fixtures/oops.yml
493
-
494
- </pre>
495
- </div>
496
- <div class="code_container">
497
- <pre class="brush: plain; gutter: false; toolbar: false">
498
- $ bin/rails destroy model Oops
499
- invoke active_record
500
- remove db/migrate/20120528062523_create_oops.rb
501
- remove app/models/oops.rb
502
- invoke test_unit
503
- remove test/models/oops_test.rb
504
- remove test/fixtures/oops.yml
505
-
506
- </pre>
507
- </div>
508
- <h3 id="rake">2 Rake</h3><p>Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and <code>.rake</code> files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.</p><p>You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing <code>rake --tasks</code>. Each task has a description, and should help you find the thing you need.</p><p>To get the full backtrace for running rake task you can pass the option
509
- <code>--trace</code> to command line, for example <code>rake db:create --trace</code>.</p><div class="code_container">
510
- <pre class="brush: plain; gutter: false; toolbar: false">
511
- $ bin/rake --tasks
512
- rake about # List versions of all Rails frameworks and the environment
513
- rake assets:clean # Remove old compiled assets
514
- rake assets:clobber # Remove compiled assets
515
- rake assets:precompile # Compile all the assets named in config.assets.precompile
516
- rake db:create # Create the database from config/database.yml for the current Rails.env
517
- ...
518
- rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
519
- rake middleware # Prints out your Rack middleware stack
520
- ...
521
- rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)
522
- rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
523
-
524
- </pre>
525
- </div>
526
- <div class="info"><p>You can also use <code>rake -T</code> to get the list of tasks.</p></div><h4 id="about">2.1 <code>about</code>
527
- </h4><p><code>rake about</code> gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version. It is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.</p><div class="code_container">
528
- <pre class="brush: plain; gutter: false; toolbar: false">
529
- $ bin/rake about
530
- About your application's environment
531
- Ruby version 1.9.3 (x86_64-linux)
532
- RubyGems version 1.3.6
533
- Rack version 1.3
534
- Rails version 4.2.0
535
- JavaScript Runtime Node.js (V8)
536
- Active Record version 4.2.0
537
- Action Pack version 4.2.0
538
- Action View version 4.2.0
539
- Action Mailer version 4.2.0
540
- Active Support version 4.2.0
541
- Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #&lt;ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd131a7c88&gt;, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
542
- Application root /home/foobar/commandsapp
543
- Environment development
544
- Database adapter sqlite3
545
- Database schema version 20110805173523
546
-
547
- </pre>
548
- </div>
549
- <h4 id="assets">2.2 <code>assets</code>
550
- </h4><p>You can precompile the assets in <code>app/assets</code> using <code>rake assets:precompile</code>,
551
- and remove older compiled assets using <code>rake assets:clean</code>. The <code>assets:clean</code>
552
- task allows for rolling deploys that may still be linking to an old asset while
553
- the new assets are being built.</p><p>If you want to clear <code>public/assets</code> completely, you can use <code>rake assets:clobber</code>.</p><h4 id="db">2.3 <code>db</code>
554
- </h4><p>The most common tasks of the <code>db:</code> Rake namespace are <code>migrate</code> and <code>create</code>, and it will pay off to try out all of the migration rake tasks (<code>up</code>, <code>down</code>, <code>redo</code>, <code>reset</code>). <code>rake db:version</code> is useful when troubleshooting, telling you the current version of the database.</p><p>More information about migrations can be found in the <a href="migrations.html">Migrations</a> guide.</p><h4 id="doc">2.4 <code>doc</code>
555
- </h4><p>The <code>doc:</code> namespace has the tools to generate documentation for your app, API documentation, guides. Documentation can also be stripped which is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform.</p>
556
- <ul>
557
- <li>
558
- <code>rake doc:app</code> generates documentation for your application in <code>doc/app</code>.</li>
559
- <li>
560
- <code>rake doc:guides</code> generates Rails guides in <code>doc/guides</code>.</li>
561
- <li>
562
- <code>rake doc:rails</code> generates API documentation for Rails in <code>doc/api</code>.</li>
563
- </ul>
564
- <h4 id="notes">2.5 <code>notes</code>
565
- </h4><p><code>rake notes</code> will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension <code>.builder</code>, <code>.rb</code>, <code>.rake</code>, <code>.yml</code>, <code>.yaml</code>, <code>.ruby</code>, <code>.css</code>, <code>.js</code> and <code>.erb</code> for both default and custom annotations.</p><div class="code_container">
566
- <pre class="brush: plain; gutter: false; toolbar: false">
567
- $ bin/rake notes
568
- (in /home/foobar/commandsapp)
569
- app/controllers/admin/users_controller.rb:
570
- * [ 20] [TODO] any other way to do this?
571
- * [132] [FIXME] high priority for next deploy
572
-
573
- app/models/school.rb:
574
- * [ 13] [OPTIMIZE] refactor this code to make it faster
575
- * [ 17] [FIXME]
576
-
577
- </pre>
578
- </div>
579
- <p>You can add support for new file extensions using <code>config.annotations.register_extensions</code> option, which receives a list of the extensions with its corresponding regex to match it up.</p><div class="code_container">
580
- <pre class="brush: ruby; gutter: false; toolbar: false">
581
- config.annotations.register_extensions("scss", "sass", "less") { |annotation| /\/\/\s*(#{annotation}):?\s*(.*)$/ }
582
-
583
- </pre>
584
- </div>
585
- <p>If you are looking for a specific annotation, say FIXME, you can use <code>rake notes:fixme</code>. Note that you have to lower case the annotation's name.</p><div class="code_container">
586
- <pre class="brush: plain; gutter: false; toolbar: false">
587
- $ bin/rake notes:fixme
588
- (in /home/foobar/commandsapp)
589
- app/controllers/admin/users_controller.rb:
590
- * [132] high priority for next deploy
591
-
592
- app/models/school.rb:
593
- * [ 17]
594
-
595
- </pre>
596
- </div>
597
- <p>You can also use custom annotations in your code and list them using <code>rake notes:custom</code> by specifying the annotation using an environment variable <code>ANNOTATION</code>.</p><div class="code_container">
598
- <pre class="brush: plain; gutter: false; toolbar: false">
599
- $ bin/rake notes:custom ANNOTATION=BUG
600
- (in /home/foobar/commandsapp)
601
- app/models/article.rb:
602
- * [ 23] Have to fix this one before pushing!
603
-
604
- </pre>
605
- </div>
606
- <div class="note"><p>When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines.</p></div><p>By default, <code>rake notes</code> will look in the <code>app</code>, <code>config</code>, <code>lib</code>, <code>bin</code> and <code>test</code> directories. If you would like to search other directories, you can provide them as a comma separated list in an environment variable <code>SOURCE_ANNOTATION_DIRECTORIES</code>.</p><div class="code_container">
607
- <pre class="brush: plain; gutter: false; toolbar: false">
608
- $ export SOURCE_ANNOTATION_DIRECTORIES='spec,vendor'
609
- $ bin/rake notes
610
- (in /home/foobar/commandsapp)
611
- app/models/user.rb:
612
- * [ 35] [FIXME] User should have a subscription at this point
613
- spec/models/user_spec.rb:
614
- * [122] [TODO] Verify the user that has a subscription works
615
-
616
- </pre>
617
- </div>
618
- <h4 id="routes">2.6 <code>routes</code>
619
- </h4><p><code>rake routes</code> will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.</p><h4 id="test">2.7 <code>test</code>
620
- </h4><div class="info"><p>A good description of unit testing in Rails is given in <a href="testing.html">A Guide to Testing Rails Applications</a></p></div><p>Rails comes with a test suite called Minitest. Rails owes its stability to the use of tests. The tasks available in the <code>test:</code> namespace helps in running the different tests you will hopefully write.</p><h4 id="tmp">2.8 <code>tmp</code>
621
- </h4><p>The <code>Rails.root/tmp</code> directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions.</p><p>The <code>tmp:</code> namespaced tasks will help you clear and create the <code>Rails.root/tmp</code> directory:</p>
622
- <ul>
623
- <li>
624
- <code>rake tmp:cache:clear</code> clears <code>tmp/cache</code>.</li>
625
- <li>
626
- <code>rake tmp:sessions:clear</code> clears <code>tmp/sessions</code>.</li>
627
- <li>
628
- <code>rake tmp:sockets:clear</code> clears <code>tmp/sockets</code>.</li>
629
- <li>
630
- <code>rake tmp:clear</code> clears all the three: cache, sessions and sockets.</li>
631
- <li>
632
- <code>rake tmp:create</code> creates tmp directories for sessions, cache, sockets, and pids.</li>
633
- </ul>
634
- <h4 id="miscellaneous">2.9 Miscellaneous</h4>
635
- <ul>
636
- <li>
637
- <code>rake stats</code> is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.</li>
638
- <li>
639
- <code>rake secret</code> will give you a pseudo-random key to use for your session secret.</li>
640
- <li>
641
- <code>rake time:zones:all</code> lists all the timezones Rails knows about.</li>
642
- </ul>
643
- <h4 id="custom-rake-tasks">2.10 Custom Rake Tasks</h4><p>Custom rake tasks have a <code>.rake</code> extension and are placed in
644
- <code>Rails.root/lib/tasks</code>. You can create these custom rake tasks with the
645
- <code>bin/rails generate task</code> command.</p><div class="code_container">
646
- <pre class="brush: ruby; gutter: false; toolbar: false">
647
- desc "I am short, but comprehensive description for my cool task"
648
- task task_name: [:prerequisite_task, :another_task_we_depend_on] do
649
- # All your magic here
650
- # Any valid Ruby code is allowed
651
- end
652
-
653
- </pre>
654
- </div>
655
- <p>To pass arguments to your custom rake task:</p><div class="code_container">
656
- <pre class="brush: ruby; gutter: false; toolbar: false">
657
- task :task_name, [:arg_1] =&gt; [:pre_1, :pre_2] do |t, args|
658
- # You can use args from here
659
- end
660
-
661
- </pre>
662
- </div>
663
- <p>You can group tasks by placing them in namespaces:</p><div class="code_container">
664
- <pre class="brush: ruby; gutter: false; toolbar: false">
665
- namespace :db do
666
- desc "This task does nothing"
667
- task :nothing do
668
- # Seriously, nothing
669
- end
670
- end
671
-
672
- </pre>
673
- </div>
674
- <p>Invocation of the tasks will look like:</p><div class="code_container">
675
- <pre class="brush: plain; gutter: false; toolbar: false">
676
- $ bin/rake task_name
677
- $ bin/rake "task_name[value 1]" # entire argument string should be quoted
678
- $ bin/rake db:nothing
679
-
680
- </pre>
681
- </div>
682
- <div class="note"><p>If your need to interact with your application models, perform database queries and so on, your task should depend on the <code>environment</code> task, which will load your application code.</p></div><h3 id="the-rails-advanced-command-line">3 The Rails Advanced Command Line</h3><p>More advanced use of the command line is focused around finding useful (even surprising at times) options in the utilities, and fitting those to your needs and specific work flow. Listed here are some tricks up Rails' sleeve.</p><h4 id="rails-with-databases-and-scm">3.1 Rails with Databases and SCM</h4><p>When creating a new Rails application, you have the option to specify what kind of database and what kind of source code management system your application is going to use. This will save you a few minutes, and certainly many keystrokes.</p><p>Let's see what a <code>--git</code> option and a <code>--database=postgresql</code> option will do for us:</p><div class="code_container">
683
- <pre class="brush: plain; gutter: false; toolbar: false">
684
- $ mkdir gitapp
685
- $ cd gitapp
686
- $ git init
687
- Initialized empty Git repository in .git/
688
- $ rails new . --git --database=postgresql
689
- exists
690
- create app/controllers
691
- create app/helpers
692
- ...
693
- ...
694
- create tmp/cache
695
- create tmp/pids
696
- create Rakefile
697
- add 'Rakefile'
698
- create README.rdoc
699
- add 'README.rdoc'
700
- create app/controllers/application_controller.rb
701
- add 'app/controllers/application_controller.rb'
702
- create app/helpers/application_helper.rb
703
- ...
704
- create log/test.log
705
- add 'log/test.log'
706
-
707
- </pre>
708
- </div>
709
- <p>We had to create the <strong>gitapp</strong> directory and initialize an empty git repository before Rails would add files it created to our repository. Let's see what it put in our database configuration:</p><div class="code_container">
710
- <pre class="brush: plain; gutter: false; toolbar: false">
711
- $ cat config/database.yml
712
- # PostgreSQL. Versions 8.2 and up are supported.
713
- #
714
- # Install the pg driver:
715
- # gem install pg
716
- # On OS X with Homebrew:
717
- # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
718
- # On OS X with MacPorts:
719
- # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
720
- # On Windows:
721
- # gem install pg
722
- # Choose the win32 build.
723
- # Install PostgreSQL and put its /bin directory on your path.
724
- #
725
- # Configure Using Gemfile
726
- # gem 'pg'
727
- #
728
- development:
729
- adapter: postgresql
730
- encoding: unicode
731
- database: gitapp_development
732
- pool: 5
733
- username: gitapp
734
- password:
735
- ...
736
- ...
737
-
738
- </pre>
739
- </div>
740
- <p>It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database.</p><div class="note"><p>The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the <code>rails new</code> command to generate the basis of your app.</p></div>
741
-
742
- <h3>Feedback</h3>
743
- <p>
744
- You're encouraged to help improve the quality of this guide.
745
- </p>
746
- <p>
747
- Please contribute if you see any typos or factual errors.
748
- 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.
749
- </p>
750
- <p>
751
- You may also find incomplete content, or stuff that is not up to date.
752
- Please do add any missing documentation for master. Make sure to check
753
- <a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
754
- if the issues are already fixed or not on the master branch.
755
- Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
756
- for style and conventions.
757
- </p>
758
- <p>
759
- If for whatever reason you spot something to fix but cannot patch it yourself, please
760
- <a href="https://github.com/rails/rails/issues">open an issue</a>.
761
- </p>
762
- <p>And last but not least, any kind of discussion regarding Ruby on Rails
763
- documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
764
- </p>
765
- </div>
766
- </div>
767
- </div>
768
-
769
- <hr class="hide" />
770
- <div id="footer">
771
- <div class="wrapper">
772
- <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>
773
- <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
774
-
775
- </div>
776
- </div>
777
-
778
- <script type="text/javascript" src="javascripts/jquery.min.js"></script>
779
- <script type="text/javascript" src="javascripts/responsive-tables.js"></script>
780
- <script type="text/javascript" src="javascripts/guides.js"></script>
781
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
782
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
783
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
784
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
785
- <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
786
- <script type="text/javascript">
787
- SyntaxHighlighter.all();
788
- $(guidesIndex.bind);
789
- </script>
790
- </body>
791
- </html>