rails 4.1.4 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +55 -34
  3. metadata +93 -311
  4. data/guides/CHANGELOG.md +0 -41
  5. data/guides/Rakefile +0 -77
  6. data/guides/assets/images/akshaysurve.jpg +0 -0
  7. data/guides/assets/images/belongs_to.png +0 -0
  8. data/guides/assets/images/book_icon.gif +0 -0
  9. data/guides/assets/images/bullet.gif +0 -0
  10. data/guides/assets/images/chapters_icon.gif +0 -0
  11. data/guides/assets/images/check_bullet.gif +0 -0
  12. data/guides/assets/images/credits_pic_blank.gif +0 -0
  13. data/guides/assets/images/csrf.png +0 -0
  14. data/guides/assets/images/edge_badge.png +0 -0
  15. data/guides/assets/images/favicon.ico +0 -0
  16. data/guides/assets/images/feature_tile.gif +0 -0
  17. data/guides/assets/images/footer_tile.gif +0 -0
  18. data/guides/assets/images/fxn.png +0 -0
  19. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  20. data/guides/assets/images/getting_started/challenge.png +0 -0
  21. data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
  22. data/guides/assets/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  23. data/guides/assets/images/getting_started/form_with_errors.png +0 -0
  24. data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
  25. data/guides/assets/images/getting_started/new_article.png +0 -0
  26. data/guides/assets/images/getting_started/rails_welcome.png +0 -0
  27. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  28. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  29. data/guides/assets/images/getting_started/show_action_for_articles.png +0 -0
  30. data/guides/assets/images/getting_started/template_is_missing_articles_new.png +0 -0
  31. data/guides/assets/images/getting_started/unknown_action_create_for_articles.png +0 -0
  32. data/guides/assets/images/getting_started/unknown_action_new_for_articles.png +0 -0
  33. data/guides/assets/images/grey_bullet.gif +0 -0
  34. data/guides/assets/images/habtm.png +0 -0
  35. data/guides/assets/images/has_many.png +0 -0
  36. data/guides/assets/images/has_many_through.png +0 -0
  37. data/guides/assets/images/has_one.png +0 -0
  38. data/guides/assets/images/has_one_through.png +0 -0
  39. data/guides/assets/images/header_backdrop.png +0 -0
  40. data/guides/assets/images/header_tile.gif +0 -0
  41. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  42. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  43. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  44. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  45. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  46. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  47. data/guides/assets/images/icons/README +0 -5
  48. data/guides/assets/images/icons/callouts/1.png +0 -0
  49. data/guides/assets/images/icons/callouts/10.png +0 -0
  50. data/guides/assets/images/icons/callouts/11.png +0 -0
  51. data/guides/assets/images/icons/callouts/12.png +0 -0
  52. data/guides/assets/images/icons/callouts/13.png +0 -0
  53. data/guides/assets/images/icons/callouts/14.png +0 -0
  54. data/guides/assets/images/icons/callouts/15.png +0 -0
  55. data/guides/assets/images/icons/callouts/2.png +0 -0
  56. data/guides/assets/images/icons/callouts/3.png +0 -0
  57. data/guides/assets/images/icons/callouts/4.png +0 -0
  58. data/guides/assets/images/icons/callouts/5.png +0 -0
  59. data/guides/assets/images/icons/callouts/6.png +0 -0
  60. data/guides/assets/images/icons/callouts/7.png +0 -0
  61. data/guides/assets/images/icons/callouts/8.png +0 -0
  62. data/guides/assets/images/icons/callouts/9.png +0 -0
  63. data/guides/assets/images/icons/caution.png +0 -0
  64. data/guides/assets/images/icons/example.png +0 -0
  65. data/guides/assets/images/icons/home.png +0 -0
  66. data/guides/assets/images/icons/important.png +0 -0
  67. data/guides/assets/images/icons/next.png +0 -0
  68. data/guides/assets/images/icons/note.png +0 -0
  69. data/guides/assets/images/icons/prev.png +0 -0
  70. data/guides/assets/images/icons/tip.png +0 -0
  71. data/guides/assets/images/icons/up.png +0 -0
  72. data/guides/assets/images/icons/warning.png +0 -0
  73. data/guides/assets/images/nav_arrow.gif +0 -0
  74. data/guides/assets/images/oscardelben.jpg +0 -0
  75. data/guides/assets/images/polymorphic.png +0 -0
  76. data/guides/assets/images/radar.png +0 -0
  77. data/guides/assets/images/rails4_features.png +0 -0
  78. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  79. data/guides/assets/images/rails_guides_logo.gif +0 -0
  80. data/guides/assets/images/rails_logo_remix.gif +0 -0
  81. data/guides/assets/images/session_fixation.png +0 -0
  82. data/guides/assets/images/tab_grey.gif +0 -0
  83. data/guides/assets/images/tab_info.gif +0 -0
  84. data/guides/assets/images/tab_note.gif +0 -0
  85. data/guides/assets/images/tab_red.gif +0 -0
  86. data/guides/assets/images/tab_yellow.gif +0 -0
  87. data/guides/assets/images/tab_yellow.png +0 -0
  88. data/guides/assets/images/vijaydev.jpg +0 -0
  89. data/guides/assets/javascripts/guides.js +0 -53
  90. data/guides/assets/javascripts/jquery.min.js +0 -4
  91. data/guides/assets/javascripts/responsive-tables.js +0 -43
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  102. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  103. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  104. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  105. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  106. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  107. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  108. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  109. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  110. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  111. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  112. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  113. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  114. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  115. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  116. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  117. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +0 -17
  118. data/guides/assets/stylesheets/fixes.css +0 -16
  119. data/guides/assets/stylesheets/kindle.css +0 -11
  120. data/guides/assets/stylesheets/main.css +0 -710
  121. data/guides/assets/stylesheets/print.css +0 -52
  122. data/guides/assets/stylesheets/reset.css +0 -43
  123. data/guides/assets/stylesheets/responsive-tables.css +0 -50
  124. data/guides/assets/stylesheets/style.css +0 -13
  125. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +0 -226
  126. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  127. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  128. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  129. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  130. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  131. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  132. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  133. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  134. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  135. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  136. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  137. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  138. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  139. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  140. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  141. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  142. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  143. data/guides/bug_report_templates/action_controller_gem.rb +0 -47
  144. data/guides/bug_report_templates/action_controller_master.rb +0 -53
  145. data/guides/bug_report_templates/active_record_gem.rb +0 -40
  146. data/guides/bug_report_templates/active_record_master.rb +0 -49
  147. data/guides/code/getting_started/Gemfile +0 -40
  148. data/guides/code/getting_started/Gemfile.lock +0 -125
  149. data/guides/code/getting_started/README.rdoc +0 -28
  150. data/guides/code/getting_started/Rakefile +0 -6
  151. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  152. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  153. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  154. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  155. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  156. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  157. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  158. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  159. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  160. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  161. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  162. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  163. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  164. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  165. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  166. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  167. data/guides/code/getting_started/app/models/comment.rb +0 -3
  168. data/guides/code/getting_started/app/models/post.rb +0 -7
  169. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  170. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  171. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  172. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  173. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  174. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  175. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  176. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  177. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  178. data/guides/code/getting_started/bin/bundle +0 -4
  179. data/guides/code/getting_started/bin/rails +0 -4
  180. data/guides/code/getting_started/bin/rake +0 -4
  181. data/guides/code/getting_started/config/application.rb +0 -18
  182. data/guides/code/getting_started/config/boot.rb +0 -4
  183. data/guides/code/getting_started/config/database.yml +0 -25
  184. data/guides/code/getting_started/config/environment.rb +0 -5
  185. data/guides/code/getting_started/config/environments/development.rb +0 -30
  186. data/guides/code/getting_started/config/environments/production.rb +0 -80
  187. data/guides/code/getting_started/config/environments/test.rb +0 -36
  188. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  189. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  190. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  191. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  192. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  193. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  194. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  195. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  196. data/guides/code/getting_started/config/locales/en.yml +0 -23
  197. data/guides/code/getting_started/config/routes.rb +0 -7
  198. data/guides/code/getting_started/config.ru +0 -4
  199. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  200. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  201. data/guides/code/getting_started/db/schema.rb +0 -33
  202. data/guides/code/getting_started/db/seeds.rb +0 -7
  203. data/guides/code/getting_started/public/404.html +0 -60
  204. data/guides/code/getting_started/public/422.html +0 -60
  205. data/guides/code/getting_started/public/500.html +0 -59
  206. data/guides/code/getting_started/public/favicon.ico +0 -0
  207. data/guides/code/getting_started/public/robots.txt +0 -5
  208. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  209. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  210. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  211. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  212. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  213. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  214. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  215. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  216. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  217. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  218. data/guides/code/getting_started/test/test_helper.rb +0 -12
  219. data/guides/rails_guides/generator.rb +0 -248
  220. data/guides/rails_guides/helpers.rb +0 -53
  221. data/guides/rails_guides/indexer.rb +0 -68
  222. data/guides/rails_guides/kindle.rb +0 -119
  223. data/guides/rails_guides/levenshtein.rb +0 -31
  224. data/guides/rails_guides/markdown/renderer.rb +0 -82
  225. data/guides/rails_guides/markdown.rb +0 -163
  226. data/guides/rails_guides.rb +0 -63
  227. data/guides/source/2_2_release_notes.md +0 -435
  228. data/guides/source/2_3_release_notes.md +0 -621
  229. data/guides/source/3_0_release_notes.md +0 -611
  230. data/guides/source/3_1_release_notes.md +0 -556
  231. data/guides/source/3_2_release_notes.md +0 -565
  232. data/guides/source/4_0_release_notes.md +0 -276
  233. data/guides/source/4_1_release_notes.md +0 -731
  234. data/guides/source/_license.html.erb +0 -2
  235. data/guides/source/_welcome.html.erb +0 -25
  236. data/guides/source/action_controller_overview.md +0 -1175
  237. data/guides/source/action_mailer_basics.md +0 -689
  238. data/guides/source/action_view_overview.md +0 -1610
  239. data/guides/source/active_model_basics.md +0 -200
  240. data/guides/source/active_record_basics.md +0 -373
  241. data/guides/source/active_record_callbacks.md +0 -410
  242. data/guides/source/active_record_querying.md +0 -1773
  243. data/guides/source/active_record_validations.md +0 -1169
  244. data/guides/source/active_support_core_extensions.md +0 -3864
  245. data/guides/source/active_support_instrumentation.md +0 -496
  246. data/guides/source/api_documentation_guidelines.md +0 -315
  247. data/guides/source/asset_pipeline.md +0 -1163
  248. data/guides/source/association_basics.md +0 -2229
  249. data/guides/source/caching_with_rails.md +0 -354
  250. data/guides/source/command_line.md +0 -603
  251. data/guides/source/configuring.md +0 -942
  252. data/guides/source/contributing_to_ruby_on_rails.md +0 -544
  253. data/guides/source/credits.html.erb +0 -80
  254. data/guides/source/debugging_rails_applications.md +0 -707
  255. data/guides/source/development_dependencies_install.md +0 -278
  256. data/guides/source/documents.yaml +0 -193
  257. data/guides/source/engines.md +0 -1391
  258. data/guides/source/form_helpers.md +0 -1001
  259. data/guides/source/generators.md +0 -663
  260. data/guides/source/getting_started.md +0 -1947
  261. data/guides/source/i18n.md +0 -1043
  262. data/guides/source/index.html.erb +0 -27
  263. data/guides/source/initialization.md +0 -657
  264. data/guides/source/kindle/copyright.html.erb +0 -1
  265. data/guides/source/kindle/layout.html.erb +0 -27
  266. data/guides/source/kindle/rails_guides.opf.erb +0 -52
  267. data/guides/source/kindle/toc.html.erb +0 -24
  268. data/guides/source/kindle/toc.ncx.erb +0 -64
  269. data/guides/source/kindle/welcome.html.erb +0 -5
  270. data/guides/source/layout.html.erb +0 -146
  271. data/guides/source/layouts_and_rendering.md +0 -1226
  272. data/guides/source/maintenance_policy.md +0 -56
  273. data/guides/source/migrations.md +0 -1109
  274. data/guides/source/nested_model_forms.md +0 -225
  275. data/guides/source/plugins.md +0 -444
  276. data/guides/source/rails_application_templates.md +0 -248
  277. data/guides/source/rails_on_rack.md +0 -333
  278. data/guides/source/routing.md +0 -1115
  279. data/guides/source/ruby_on_rails_guides_guidelines.md +0 -128
  280. data/guides/source/security.md +0 -1018
  281. data/guides/source/testing.md +0 -1052
  282. data/guides/source/upgrading_ruby_on_rails.md +0 -899
  283. data/guides/source/working_with_javascript_in_rails.md +0 -405
  284. data/guides/w3c_validator.rb +0 -95
@@ -1,603 +0,0 @@
1
- The Rails Command Line
2
- ======================
3
-
4
- After reading this guide, you will know:
5
-
6
- * How to create a Rails application.
7
- * How to generate models, controllers, database migrations, and unit tests.
8
- * How to start a development server.
9
- * How to experiment with objects through an interactive shell.
10
- * How to profile and benchmark your new creation.
11
-
12
- --------------------------------------------------------------------------------
13
-
14
- NOTE: This tutorial assumes you have basic Rails knowledge from reading the [Getting Started with Rails Guide](getting_started.html).
15
-
16
- Command Line Basics
17
- -------------------
18
-
19
- 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:
20
-
21
- * `rails console`
22
- * `rails server`
23
- * `rake`
24
- * `rails generate`
25
- * `rails dbconsole`
26
- * `rails new app_name`
27
-
28
- All commands can run with ```-h or --help``` to list more information.
29
-
30
- Let's create a simple Rails application to step through each of these commands in context.
31
-
32
- ### `rails new`
33
-
34
- The first thing we'll want to do is create a new Rails application by running the `rails new` command after installing Rails.
35
-
36
- INFO: You can install the rails gem by typing `gem install rails`, if you don't have it already.
37
-
38
- ```bash
39
- $ rails new commandsapp
40
- create
41
- create README.rdoc
42
- create Rakefile
43
- create config.ru
44
- create .gitignore
45
- create Gemfile
46
- create app
47
- ...
48
- create tmp/cache
49
- ...
50
- run bundle install
51
- ```
52
-
53
- 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.
54
-
55
- ### `rails server`
56
-
57
- The `rails server` 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.
58
-
59
- With no further work, `rails server` will run our new shiny Rails app:
60
-
61
- ```bash
62
- $ cd commandsapp
63
- $ bin/rails server
64
- => Booting WEBrick
65
- => Rails 4.0.0 application starting in development on http://0.0.0.0:3000
66
- => Call with -d to detach
67
- => Ctrl-C to shutdown server
68
- [2013-08-07 02:00:01] INFO WEBrick 1.3.1
69
- [2013-08-07 02:00:01] INFO ruby 2.0.0 (2013-06-27) [x86_64-darwin11.2.0]
70
- [2013-08-07 02:00:01] INFO WEBrick::HTTPServer#start: pid=69680 port=3000
71
- ```
72
-
73
- With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open [http://localhost:3000](http://localhost:3000), you will see a basic Rails app running.
74
-
75
- INFO: You can also use the alias "s" to start the server: `rails s`.
76
-
77
- The server can be run on a different port using the `-p` option. The default development environment can be changed using `-e`.
78
-
79
- ```bash
80
- $ bin/rails server -e production -p 4000
81
- ```
82
-
83
- The `-b` option binds Rails to the specified IP, by default it is 0.0.0.0. You can run a server as a daemon by passing a `-d` option.
84
-
85
- ### `rails generate`
86
-
87
- The `rails generate` command uses templates to create a whole lot of things. Running `rails generate` by itself gives a list of available generators:
88
-
89
- INFO: You can also use the alias "g" to invoke the generator command: `rails g`.
90
-
91
- ```bash
92
- $ bin/rails generate
93
- Usage: rails generate GENERATOR [args] [options]
94
-
95
- ...
96
- ...
97
-
98
- Please choose a generator below.
99
-
100
- Rails:
101
- assets
102
- controller
103
- generator
104
- ...
105
- ...
106
- ```
107
-
108
- NOTE: You can install more generators through generator gems, portions of plugins you'll undoubtedly install, and you can even create your own!
109
-
110
- Using generators will save you a large amount of time by writing **boilerplate code**, code that is necessary for the app to work.
111
-
112
- Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator:
113
-
114
- INFO: All Rails console utilities have help text. As with most *nix utilities, you can try adding `--help` or `-h` to the end, for example `rails server --help`.
115
-
116
- ```bash
117
- $ bin/rails generate controller
118
- Usage: rails generate controller NAME [action action] [options]
119
-
120
- ...
121
- ...
122
-
123
- Description:
124
- ...
125
-
126
- To create a controller within a module, specify the controller name as a
127
- path like 'parent_module/controller_name'.
128
-
129
- ...
130
-
131
- Example:
132
- `rails generate controller CreditCard open debit credit close`
133
-
134
- Credit card controller with URLs like /credit_card/debit.
135
- Controller: app/controllers/credit_card_controller.rb
136
- Test: test/controllers/credit_card_controller_test.rb
137
- Views: app/views/credit_card/debit.html.erb [...]
138
- Helper: app/helpers/credit_card_helper.rb
139
- ```
140
-
141
- The controller generator is expecting parameters in the form of `generate controller ControllerName action1 action2`. Let's make a `Greetings` controller with an action of **hello**, which will say something nice to us.
142
-
143
- ```bash
144
- $ bin/rails generate controller Greetings hello
145
- create app/controllers/greetings_controller.rb
146
- route get "greetings/hello"
147
- invoke erb
148
- create app/views/greetings
149
- create app/views/greetings/hello.html.erb
150
- invoke test_unit
151
- create test/controllers/greetings_controller_test.rb
152
- invoke helper
153
- create app/helpers/greetings_helper.rb
154
- invoke test_unit
155
- create test/helpers/greetings_helper_test.rb
156
- invoke assets
157
- invoke coffee
158
- create app/assets/javascripts/greetings.js.coffee
159
- invoke scss
160
- create app/assets/stylesheets/greetings.css.scss
161
- ```
162
-
163
- 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.
164
-
165
- Check out the controller and modify it a little (in `app/controllers/greetings_controller.rb`):
166
-
167
- ```ruby
168
- class GreetingsController < ApplicationController
169
- def hello
170
- @message = "Hello, how are you today?"
171
- end
172
- end
173
- ```
174
-
175
- Then the view, to display our message (in `app/views/greetings/hello.html.erb`):
176
-
177
- ```erb
178
- <h1>A Greeting for You!</h1>
179
- <p><%= @message %></p>
180
- ```
181
-
182
- Fire up your server using `rails server`.
183
-
184
- ```bash
185
- $ bin/rails server
186
- => Booting WEBrick...
187
- ```
188
-
189
- The URL will be [http://localhost:3000/greetings/hello](http://localhost:3000/greetings/hello).
190
-
191
- INFO: 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 **index** action of that controller.
192
-
193
- Rails comes with a generator for data models too.
194
-
195
- ```bash
196
- $ bin/rails generate model
197
- Usage:
198
- rails generate model NAME [field[:type][:index] field[:type][:index]] [options]
199
-
200
- ...
201
-
202
- Active Record options:
203
- [--migration] # Indicates when to generate migration
204
- # Default: true
205
-
206
- ...
207
-
208
- Description:
209
- Create rails files for model generator.
210
- ```
211
-
212
- NOTE: For a list of available field types, refer to the [API documentation](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column) for the column method for the `TableDefinition` class.
213
-
214
- But instead of generating a model directly (which we'll be doing later), let's set up a scaffold. A **scaffold** 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.
215
-
216
- We will set up a simple resource called "HighScore" that will keep track of our highest score on video games we play.
217
-
218
- ```bash
219
- $ bin/rails generate scaffold HighScore game:string score:integer
220
- invoke active_record
221
- create db/migrate/20130717151933_create_high_scores.rb
222
- create app/models/high_score.rb
223
- invoke test_unit
224
- create test/models/high_score_test.rb
225
- create test/fixtures/high_scores.yml
226
- invoke resource_route
227
- route resources :high_scores
228
- invoke scaffold_controller
229
- create app/controllers/high_scores_controller.rb
230
- invoke erb
231
- create app/views/high_scores
232
- create app/views/high_scores/index.html.erb
233
- create app/views/high_scores/edit.html.erb
234
- create app/views/high_scores/show.html.erb
235
- create app/views/high_scores/new.html.erb
236
- create app/views/high_scores/_form.html.erb
237
- invoke test_unit
238
- create test/controllers/high_scores_controller_test.rb
239
- invoke helper
240
- create app/helpers/high_scores_helper.rb
241
- invoke test_unit
242
- create test/helpers/high_scores_helper_test.rb
243
- invoke jbuilder
244
- create app/views/high_scores/index.json.jbuilder
245
- create app/views/high_scores/show.json.jbuilder
246
- invoke assets
247
- invoke coffee
248
- create app/assets/javascripts/high_scores.js.coffee
249
- invoke scss
250
- create app/assets/stylesheets/high_scores.css.scss
251
- invoke scss
252
- identical app/assets/stylesheets/scaffolds.css.scss
253
- ```
254
-
255
- 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 `high_scores` table and fields), takes care of the route for the **resource**, and new tests for everything.
256
-
257
- The migration requires that we **migrate**, that is, run some Ruby code (living in that `20130717151933_create_high_scores.rb`) to modify the schema of our database. Which database? The sqlite3 database that Rails will create for you when we run the `rake db:migrate` command. We'll talk more about Rake in-depth in a little while.
258
-
259
- ```bash
260
- $ bin/rake db:migrate
261
- == CreateHighScores: migrating ===============================================
262
- -- create_table(:high_scores)
263
- -> 0.0017s
264
- == CreateHighScores: migrated (0.0019s) ======================================
265
- ```
266
-
267
- INFO: 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.
268
-
269
- Let's see the interface Rails created for us.
270
-
271
- ```bash
272
- $ bin/rails server
273
- ```
274
-
275
- Go to your browser and open [http://localhost:3000/high_scores](http://localhost:3000/high_scores), now we can create new high scores (55,160 on Space Invaders!)
276
-
277
- ### `rails console`
278
-
279
- The `console` command lets you interact with your Rails application from the command line. On the underside, `rails console` 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.
280
-
281
- INFO: You can also use the alias "c" to invoke the console: `rails c`.
282
-
283
- You can specify the environment in which the `console` command should operate.
284
-
285
- ```bash
286
- $ bin/rails console staging
287
- ```
288
-
289
- If you wish to test out some code without changing any data, you can do that by invoking `rails console --sandbox`.
290
-
291
- ```bash
292
- $ bin/rails console --sandbox
293
- Loading development environment in sandbox (Rails 4.0.0)
294
- Any modifications you make will be rolled back on exit
295
- irb(main):001:0>
296
- ```
297
-
298
- ### `rails dbconsole`
299
-
300
- `rails dbconsole` 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.
301
-
302
- INFO: You can also use the alias "db" to invoke the dbconsole: `rails db`.
303
-
304
- ### `rails runner`
305
-
306
- `runner` runs Ruby code in the context of Rails non-interactively. For instance:
307
-
308
- ```bash
309
- $ bin/rails runner "Model.long_running_method"
310
- ```
311
-
312
- INFO: You can also use the alias "r" to invoke the runner: `rails r`.
313
-
314
- You can specify the environment in which the `runner` command should operate using the `-e` switch.
315
-
316
- ```bash
317
- $ bin/rails runner -e staging "Model.long_running_method"
318
- ```
319
-
320
- ### `rails destroy`
321
-
322
- Think of `destroy` as the opposite of `generate`. It'll figure out what generate did, and undo it.
323
-
324
- INFO: You can also use the alias "d" to invoke the destroy command: `rails d`.
325
-
326
- ```bash
327
- $ bin/rails generate model Oops
328
- invoke active_record
329
- create db/migrate/20120528062523_create_oops.rb
330
- create app/models/oops.rb
331
- invoke test_unit
332
- create test/models/oops_test.rb
333
- create test/fixtures/oops.yml
334
- ```
335
- ```bash
336
- $ bin/rails destroy model Oops
337
- invoke active_record
338
- remove db/migrate/20120528062523_create_oops.rb
339
- remove app/models/oops.rb
340
- invoke test_unit
341
- remove test/models/oops_test.rb
342
- remove test/fixtures/oops.yml
343
- ```
344
-
345
- Rake
346
- ----
347
-
348
- Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and `.rake` 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.
349
-
350
- You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing `rake --tasks`. Each task has a description, and should help you find the thing you need.
351
-
352
- To get the full backtrace for running rake task you can pass the option
353
- ```--trace``` to command line, for example ```rake db:create --trace```.
354
-
355
- ```bash
356
- $ bin/rake --tasks
357
- rake about # List versions of all Rails frameworks and the environment
358
- rake assets:clean # Remove compiled assets
359
- rake assets:precompile # Compile all the assets named in config.assets.precompile
360
- rake db:create # Create the database from config/database.yml for the current Rails.env
361
- ...
362
- rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
363
- rake middleware # Prints out your Rack middleware stack
364
- ...
365
- rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)
366
- rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
367
- ```
368
- INFO: You can also use ```rake -T``` to get the list of tasks.
369
-
370
- ### `about`
371
-
372
- `rake about` gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version. It is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.
373
-
374
- ```bash
375
- $ bin/rake about
376
- About your application's environment
377
- Ruby version 1.9.3 (x86_64-linux)
378
- RubyGems version 1.3.6
379
- Rack version 1.3
380
- Rails version 4.1.1
381
- JavaScript Runtime Node.js (V8)
382
- Active Record version 4.1.1
383
- Action Pack version 4.1.1
384
- Action View version 4.1.1
385
- Action Mailer version 4.1.1
386
- Active Support version 4.1.1
387
- Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd131a7c88>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
388
- Application root /home/foobar/commandsapp
389
- Environment development
390
- Database adapter sqlite3
391
- Database schema version 20110805173523
392
- ```
393
-
394
- ### `assets`
395
-
396
- You can precompile the assets in `app/assets` using `rake assets:precompile` and remove those compiled assets using `rake assets:clean`.
397
-
398
- ### `db`
399
-
400
- The most common tasks of the `db:` Rake namespace are `migrate` and `create`, and it will pay off to try out all of the migration rake tasks (`up`, `down`, `redo`, `reset`). `rake db:version` is useful when troubleshooting, telling you the current version of the database.
401
-
402
- More information about migrations can be found in the [Migrations](migrations.html) guide.
403
-
404
- ### `doc`
405
-
406
- The `doc:` 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.
407
-
408
- * `rake doc:app` generates documentation for your application in `doc/app`.
409
- * `rake doc:guides` generates Rails guides in `doc/guides`.
410
- * `rake doc:rails` generates API documentation for Rails in `doc/api`.
411
-
412
- ### `notes`
413
-
414
- `rake notes` will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension `.builder`, `.rb`, `.erb`, `.haml` and `.slim` for both default and custom annotations.
415
-
416
- ```bash
417
- $ bin/rake notes
418
- (in /home/foobar/commandsapp)
419
- app/controllers/admin/users_controller.rb:
420
- * [ 20] [TODO] any other way to do this?
421
- * [132] [FIXME] high priority for next deploy
422
-
423
- app/models/school.rb:
424
- * [ 13] [OPTIMIZE] refactor this code to make it faster
425
- * [ 17] [FIXME]
426
- ```
427
-
428
- If you are looking for a specific annotation, say FIXME, you can use `rake notes:fixme`. Note that you have to lower case the annotation's name.
429
-
430
- ```bash
431
- $ bin/rake notes:fixme
432
- (in /home/foobar/commandsapp)
433
- app/controllers/admin/users_controller.rb:
434
- * [132] high priority for next deploy
435
-
436
- app/models/school.rb:
437
- * [ 17]
438
- ```
439
-
440
- You can also use custom annotations in your code and list them using `rake notes:custom` by specifying the annotation using an environment variable `ANNOTATION`.
441
-
442
- ```bash
443
- $ bin/rake notes:custom ANNOTATION=BUG
444
- (in /home/foobar/commandsapp)
445
- app/models/post.rb:
446
- * [ 23] Have to fix this one before pushing!
447
- ```
448
-
449
- NOTE. When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines.
450
-
451
- By default, `rake notes` will look in the `app`, `config`, `lib`, `bin` and `test` directories. If you would like to search other directories, you can provide them as a comma separated list in an environment variable `SOURCE_ANNOTATION_DIRECTORIES`.
452
-
453
- ```bash
454
- $ export SOURCE_ANNOTATION_DIRECTORIES='spec,vendor'
455
- $ bin/rake notes
456
- (in /home/foobar/commandsapp)
457
- app/models/user.rb:
458
- * [ 35] [FIXME] User should have a subscription at this point
459
- spec/models/user_spec.rb:
460
- * [122] [TODO] Verify the user that has a subscription works
461
- ```
462
-
463
- ### `routes`
464
-
465
- `rake routes` 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.
466
-
467
- ### `test`
468
-
469
- INFO: A good description of unit testing in Rails is given in [A Guide to Testing Rails Applications](testing.html)
470
-
471
- Rails comes with a test suite called Minitest. Rails owes its stability to the use of tests. The tasks available in the `test:` namespace helps in running the different tests you will hopefully write.
472
-
473
- ### `tmp`
474
-
475
- The `Rails.root/tmp` 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.
476
-
477
- The `tmp:` namespaced tasks will help you clear and create the `Rails.root/tmp` directory:
478
-
479
- * `rake tmp:cache:clear` clears `tmp/cache`.
480
- * `rake tmp:sessions:clear` clears `tmp/sessions`.
481
- * `rake tmp:sockets:clear` clears `tmp/sockets`.
482
- * `rake tmp:clear` clears all the three: cache, sessions and sockets.
483
- * `rake tmp:create` creates tmp directories for sessions, cache, sockets, and pids.
484
-
485
- ### Miscellaneous
486
-
487
- * `rake stats` is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.
488
- * `rake secret` will give you a pseudo-random key to use for your session secret.
489
- * `rake time:zones:all` lists all the timezones Rails knows about.
490
-
491
- ### Custom Rake Tasks
492
-
493
- Custom rake tasks have a `.rake` extension and are placed in
494
- `Rails.root/lib/tasks`. You can create these custom rake tasks with the
495
- `bin/rails generate task` command.
496
-
497
- ```ruby
498
- desc "I am short, but comprehensive description for my cool task"
499
- task task_name: [:prerequisite_task, :another_task_we_depend_on] do
500
- # All your magic here
501
- # Any valid Ruby code is allowed
502
- end
503
- ```
504
-
505
- To pass arguments to your custom rake task:
506
-
507
- ```ruby
508
- task :task_name, [:arg_1] => [:pre_1, :pre_2] do |t, args|
509
- # You can use args from here
510
- end
511
- ```
512
-
513
- You can group tasks by placing them in namespaces:
514
-
515
- ```ruby
516
- namespace :db do
517
- desc "This task does nothing"
518
- task :nothing do
519
- # Seriously, nothing
520
- end
521
- end
522
- ```
523
-
524
- Invocation of the tasks will look like:
525
-
526
- ```bash
527
- $ bin/rake task_name
528
- $ bin/rake "task_name[value 1]" # entire argument string should be quoted
529
- $ bin/rake db:nothing
530
- ```
531
-
532
- NOTE: If your need to interact with your application models, perform database queries and so on, your task should depend on the `environment` task, which will load your application code.
533
-
534
- The Rails Advanced Command Line
535
- -------------------------------
536
-
537
- 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.
538
-
539
- ### Rails with Databases and SCM
540
-
541
- 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.
542
-
543
- Let's see what a `--git` option and a `--database=postgresql` option will do for us:
544
-
545
- ```bash
546
- $ mkdir gitapp
547
- $ cd gitapp
548
- $ git init
549
- Initialized empty Git repository in .git/
550
- $ rails new . --git --database=postgresql
551
- exists
552
- create app/controllers
553
- create app/helpers
554
- ...
555
- ...
556
- create tmp/cache
557
- create tmp/pids
558
- create Rakefile
559
- add 'Rakefile'
560
- create README.rdoc
561
- add 'README.rdoc'
562
- create app/controllers/application_controller.rb
563
- add 'app/controllers/application_controller.rb'
564
- create app/helpers/application_helper.rb
565
- ...
566
- create log/test.log
567
- add 'log/test.log'
568
- ```
569
-
570
- We had to create the **gitapp** 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:
571
-
572
- ```bash
573
- $ cat config/database.yml
574
- # PostgreSQL. Versions 8.2 and up are supported.
575
- #
576
- # Install the pg driver:
577
- # gem install pg
578
- # On OS X with Homebrew:
579
- # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
580
- # On OS X with MacPorts:
581
- # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
582
- # On Windows:
583
- # gem install pg
584
- # Choose the win32 build.
585
- # Install PostgreSQL and put its /bin directory on your path.
586
- #
587
- # Configure Using Gemfile
588
- # gem 'pg'
589
- #
590
- development:
591
- adapter: postgresql
592
- encoding: unicode
593
- database: gitapp_development
594
- pool: 5
595
- username: gitapp
596
- password:
597
- ...
598
- ...
599
- ```
600
-
601
- It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database.
602
-
603
- NOTE. 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 `rails new` command to generate the basis of your app.