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
@@ -15,5 +15,5 @@
15
15
  </p>
16
16
  <% end %>
17
17
  <p>
18
- The guides for earlier releases: <a href="http://guides.rubyonrails.org/v4.1.4/">Rails 4.1.4</a>, <a href="http://guides.rubyonrails.org/v4.0.8/">Rails 4.0.8</a>, <a href="http://guides.rubyonrails.org/v3.2.19/">Rails 3.2.19</a> and <a href="http://guides.rubyonrails.org/v2.3.11/">Rails 2.3.11</a>.
18
+ The guides for earlier releases: <a href="http://guides.rubyonrails.org/v4.1.8/">Rails 4.1.8</a>, <a href="http://guides.rubyonrails.org/v4.0.12/">Rails 4.0.12</a>, <a href="http://guides.rubyonrails.org/v3.2.21/">Rails 3.2.21</a> and <a href="http://guides.rubyonrails.org/v2.3.11/">Rails 2.3.11</a>.
19
19
  </p>
@@ -1213,12 +1213,12 @@ Create the controller and views.
1213
1213
  * `app/views`
1214
1214
 
1215
1215
  ```
1216
- errors/
1217
- not_found.html.erb
1218
- unprocessable_entity.html.erb
1219
- server_error.html.erb
1220
- layouts/
1221
- error.html.erb
1216
+ errors/
1217
+ not_found.html.erb
1218
+ unprocessable_entity.html.erb
1219
+ server_error.html.erb
1220
+ layouts/
1221
+ error.html.erb
1222
1222
  ```
1223
1223
 
1224
1224
  Do not forget to set the correct status code on the controller as shown before.
@@ -35,10 +35,26 @@ views.
35
35
  ```bash
36
36
  $ bin/rails generate mailer UserMailer
37
37
  create app/mailers/user_mailer.rb
38
+ create app/mailers/application_mailer.rb
38
39
  invoke erb
39
40
  create app/views/user_mailer
41
+ create app/views/layouts/mailer.text.erb
42
+ create app/views/layouts/mailer.html.erb
40
43
  invoke test_unit
41
44
  create test/mailers/user_mailer_test.rb
45
+ create test/mailers/previews/user_mailer_preview.rb
46
+ ```
47
+
48
+ ```ruby
49
+ # app/mailers/application_mailer.rb
50
+ class ApplicationMailer < ActionMailer::Base
51
+ default "from@example.com"
52
+ layout 'mailer'
53
+ end
54
+
55
+ # app/mailers/user_mailer.rb
56
+ class UserMailer < ApplicationMailer
57
+ end
42
58
  ```
43
59
 
44
60
  As you can see, you can generate mailers just like you use other generators with
@@ -63,8 +79,7 @@ delivered via email.
63
79
  `app/mailers/user_mailer.rb` contains an empty mailer:
64
80
 
65
81
  ```ruby
66
- class UserMailer < ActionMailer::Base
67
- default from: 'from@example.com'
82
+ class UserMailer < ApplicationMailer
68
83
  end
69
84
  ```
70
85
 
@@ -72,7 +87,7 @@ Let's add a method called `welcome_email`, that will send an email to the user's
72
87
  registered email address:
73
88
 
74
89
  ```ruby
75
- class UserMailer < ActionMailer::Base
90
+ class UserMailer < ApplicationMailer
76
91
  default from: 'notifications@example.com'
77
92
 
78
93
  def welcome_email(user)
@@ -348,7 +363,7 @@ for the HTML version and `welcome_email.text.erb` for the plain text version.
348
363
  To change the default mailer view for your action you do something like:
349
364
 
350
365
  ```ruby
351
- class UserMailer < ActionMailer::Base
366
+ class UserMailer < ApplicationMailer
352
367
  default from: 'notifications@example.com'
353
368
 
354
369
  def welcome_email(user)
@@ -370,7 +385,7 @@ If you want more flexibility you can also pass a block and render specific
370
385
  templates or even render inline or text without using a template file:
371
386
 
372
387
  ```ruby
373
- class UserMailer < ActionMailer::Base
388
+ class UserMailer < ApplicationMailer
374
389
  default from: 'notifications@example.com'
375
390
 
376
391
  def welcome_email(user)
@@ -400,7 +415,7 @@ layout.
400
415
  In order to use a different file, call `layout` in your mailer:
401
416
 
402
417
  ```ruby
403
- class UserMailer < ActionMailer::Base
418
+ class UserMailer < ApplicationMailer
404
419
  layout 'awesome' # use awesome.(html|text).erb as the layout
405
420
  end
406
421
  ```
@@ -412,7 +427,7 @@ You can also pass in a `layout: 'layout_name'` option to the render call inside
412
427
  the format block to specify different layouts for different formats:
413
428
 
414
429
  ```ruby
415
- class UserMailer < ActionMailer::Base
430
+ class UserMailer < ApplicationMailer
416
431
  def welcome_email(user)
417
432
  mail(to: user.email) do |format|
418
433
  format.html { render layout: 'my_layout' }
@@ -510,7 +525,7 @@ while delivering emails, you can do this using `delivery_method_options` in the
510
525
  mailer action.
511
526
 
512
527
  ```ruby
513
- class UserMailer < ActionMailer::Base
528
+ class UserMailer < ApplicationMailer
514
529
  def welcome_email(user, company)
515
530
  @user = user
516
531
  @url = user_url(@user)
@@ -532,7 +547,7 @@ option. In such cases don't forget to add the `:content_type` option. Rails
532
547
  will default to `text/plain` otherwise.
533
548
 
534
549
  ```ruby
535
- class UserMailer < ActionMailer::Base
550
+ class UserMailer < ApplicationMailer
536
551
  def welcome_email(user, email_body)
537
552
  mail(to: user.email,
538
553
  body: email_body,
@@ -562,7 +577,7 @@ mailer, and pass the email object to the mailer `receive` instance
562
577
  method. Here's an example:
563
578
 
564
579
  ```ruby
565
- class UserMailer < ActionMailer::Base
580
+ class UserMailer < ApplicationMailer
566
581
  def receive(email)
567
582
  page = Page.find_by(address: email.to.first)
568
583
  page.emails.create(
@@ -598,7 +613,7 @@ Action Mailer allows for you to specify a `before_action`, `after_action` and
598
613
  using instance variables set in your mailer action.
599
614
 
600
615
  ```ruby
601
- class UserMailer < ActionMailer::Base
616
+ class UserMailer < ApplicationMailer
602
617
  after_action :set_delivery_options,
603
618
  :prevent_delivery_to_guests,
604
619
  :set_business_headers
@@ -7,7 +7,6 @@ After reading this guide, you will know:
7
7
  * How best to use templates, partials, and layouts.
8
8
  * What helpers are provided by Action View and how to make your own.
9
9
  * How to use localized views.
10
- * How to use Action View outside of Rails.
11
10
 
12
11
  --------------------------------------------------------------------------------
13
12
 
@@ -23,7 +23,7 @@ clean-ups, to billing charges, to mailings. Anything that can be chopped up
23
23
  into small units of work and run in parallel, really.
24
24
 
25
25
 
26
- The Purpose of the Active Job
26
+ The Purpose of Active Job
27
27
  -----------------------------
28
28
  The main point is to ensure that all Rails apps will have a job infrastructure
29
29
  in place, even if it's in the form of an "immediate runner". We can then have
@@ -41,10 +41,12 @@ This section will provide a step-by-step guide to creating a job and enqueuing i
41
41
  ### Create the Job
42
42
 
43
43
  Active Job provides a Rails generator to create jobs. The following will create a
44
- job in `app/jobs`:
44
+ job in `app/jobs` (with an attached test case under `test/jobs`):
45
45
 
46
46
  ```bash
47
47
  $ bin/rails generate job guests_cleanup
48
+ invoke test_unit
49
+ create test/jobs/guests_cleanup_job_test.rb
48
50
  create app/jobs/guests_cleanup_job.rb
49
51
  ```
50
52
 
@@ -52,12 +54,8 @@ You can also create a job that will run on a specific queue:
52
54
 
53
55
  ```bash
54
56
  $ bin/rails generate job guests_cleanup --queue urgent
55
- create app/jobs/guests_cleanup_job.rb
56
57
  ```
57
58
 
58
- As you can see, you can generate jobs just like you use other generators with
59
- Rails.
60
-
61
59
  If you don't want to use a generator, you could create your own file inside of
62
60
  `app/jobs`, just make sure that it inherits from `ActiveJob::Base`.
63
61
 
@@ -78,15 +76,18 @@ end
78
76
  Enqueue a job like so:
79
77
 
80
78
  ```ruby
81
- MyJob.perform_later record # Enqueue a job to be performed as soon the queueing system is free.
79
+ # Enqueue a job to be performed as soon the queueing system is free.
80
+ MyJob.perform_later record
82
81
  ```
83
82
 
84
83
  ```ruby
85
- MyJob.set(wait_until: Date.tomorrow.noon).perform_later(record) # Enqueue a job to be performed tomorrow at noon.
84
+ # Enqueue a job to be performed tomorrow at noon.
85
+ MyJob.set(wait_until: Date.tomorrow.noon).perform_later(record)
86
86
  ```
87
87
 
88
88
  ```ruby
89
- MyJob.set(wait: 1.week).perform_later(record) # Enqueue a job to be performed 1 week from now.
89
+ # Enqueue a job to be performed 1 week from now.
90
+ MyJob.set(wait: 1.week).perform_later(record)
90
91
  ```
91
92
 
92
93
  That's it!
@@ -103,14 +104,19 @@ Active Job has built-in adapters for multiple queueing backends (Sidekiq,
103
104
  Resque, Delayed Job and others). To get an up-to-date list of the adapters
104
105
  see the API Documentation for [ActiveJob::QueueAdapters](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
105
106
 
106
- ### Changing the Backend
107
+ ### Setting the Backend
107
108
 
108
- You can easily change your queueing backend:
109
+ You can easily set your queueing backend:
109
110
 
110
111
  ```ruby
111
- # be sure to have the adapter gem in your Gemfile and follow the adapter specific
112
- # installation and deployment instructions
113
- Rails.application.config.active_job.queue_adapter = :sidekiq
112
+ # config/application.rb
113
+ module YourApp
114
+ class Application < Rails::Application
115
+ # Be sure to have the adapter's gem in your Gemfile and follow
116
+ # the adapter's specific installation and deployment instructions.
117
+ config.active_job.queue_adapter = :sidekiq
118
+ end
119
+ end
114
120
  ```
115
121
 
116
122
 
@@ -145,7 +151,7 @@ class GuestsCleanupJob < ActiveJob::Base
145
151
  end
146
152
 
147
153
  # Now your job will run on queue production_low_priority on your
148
- # production environment and on beta_low_priority on your beta
154
+ # production environment and on staging_low_priority on your staging
149
155
  # environment
150
156
  ```
151
157
 
@@ -172,15 +178,15 @@ end
172
178
  # environment
173
179
  ```
174
180
 
175
- If you want more control on what queue a job will be run you can pass a :queue
176
- option to #set:
181
+ If you want more control on what queue a job will be run you can pass a `:queue`
182
+ option to `#set`:
177
183
 
178
184
  ```ruby
179
185
  MyJob.set(queue: :another_queue).perform_later(record)
180
186
  ```
181
187
 
182
- To control the queue from the job level you can pass a block to queue_as. The
183
- block will be executed in the job context (so you can access self.arguments)
188
+ To control the queue from the job level you can pass a block to `#queue_as`. The
189
+ block will be executed in the job context (so you can access `self.arguments`)
184
190
  and you must return the queue name:
185
191
 
186
192
  ```ruby
@@ -202,7 +208,6 @@ end
202
208
  ProcessVideoJob.perform_later(Video.last)
203
209
  ```
204
210
 
205
-
206
211
  NOTE: Make sure your queueing backend "listens" on your queue name. For some
207
212
  backends you need to specify the queues to listen to.
208
213
 
@@ -245,7 +250,7 @@ end
245
250
  ```
246
251
 
247
252
 
248
- ActionMailer
253
+ Action Mailer
249
254
  ------------
250
255
 
251
256
  One of the most common jobs in a modern web application is sending emails outside
@@ -263,12 +268,13 @@ UserMailer.welcome(@user).deliver_later
263
268
 
264
269
  GlobalID
265
270
  --------
271
+
266
272
  Active Job supports GlobalID for parameters. This makes it possible to pass live
267
273
  Active Record objects to your job instead of class/id pairs, which you then have
268
274
  to manually deserialize. Before, jobs would look like this:
269
275
 
270
276
  ```ruby
271
- class TrashableCleanupJob
277
+ class TrashableCleanupJob < ActiveJob::Base
272
278
  def perform(trashable_class, trashable_id, depth)
273
279
  trashable = trashable_class.constantize.find(trashable_id)
274
280
  trashable.cleanup(depth)
@@ -279,7 +285,7 @@ end
279
285
  Now you can simply do:
280
286
 
281
287
  ```ruby
282
- class TrashableCleanupJob
288
+ class TrashableCleanupJob < ActiveJob::Base
283
289
  def perform(trashable, depth)
284
290
  trashable.cleanup(depth)
285
291
  end
@@ -103,11 +103,6 @@ profile.settings # => {"color"=>"blue", "resolution"=>"800x600"}
103
103
 
104
104
  profile.settings = {"color" => "yellow", "resolution" => "1280x1024"}
105
105
  profile.save!
106
-
107
- ## you need to call _will_change! if you are editing the store in place
108
- profile.settings["color"] = "green"
109
- profile.settings_will_change!
110
- profile.save!
111
106
  ```
112
107
 
113
108
  ### JSON
@@ -219,7 +214,7 @@ Currently there is no special support for enumerated types. They are mapped as
219
214
  normal text columns:
220
215
 
221
216
  ```ruby
222
- # db/migrate/20131220144913_create_events.rb
217
+ # db/migrate/20131220144913_create_articles.rb
223
218
  execute <<-SQL
224
219
  CREATE TYPE article_status AS ENUM ('draft', 'published');
225
220
  SQL
@@ -281,7 +276,7 @@ end
281
276
  # Usage
282
277
  User.create settings: "01010011"
283
278
  user = User.first
284
- user.settings # => "(Paris,Champs-Élysées)"
279
+ user.settings # => "01010011"
285
280
  user.settings = "0xAF"
286
281
  user.settings # => 10101111
287
282
  user.save!
@@ -533,6 +533,7 @@ validates :boolean_field_name, presence: true
533
533
  validates :boolean_field_name, inclusion: { in: [true, false] }
534
534
  validates :boolean_field_name, exclusion: { in: [nil] }
535
535
  ```
536
+
536
537
  By using one of these validations, you will ensure the value will NOT be `nil`
537
538
  which would result in a `NULL` value in most cases.
538
539
 
@@ -1011,7 +1011,7 @@ self.default_params = {
1011
1011
  }.freeze
1012
1012
  ```
1013
1013
 
1014
- They can be also accessed and overridden at the instance level.
1014
+ They can also be accessed and overridden at the instance level.
1015
1015
 
1016
1016
  ```ruby
1017
1017
  A.x = 1
@@ -225,11 +225,11 @@ Active Record
225
225
 
226
226
  ### sql.active_record
227
227
 
228
- | Key | Value |
229
- | ------------ | --------------------- |
230
- | `:sql` | SQL statement |
231
- | `:name` | Name of the operation |
232
- | `:object_id` | `self.object_id` |
228
+ | Key | Value |
229
+ | ---------------- | --------------------- |
230
+ | `:sql` | SQL statement |
231
+ | `:name` | Name of the operation |
232
+ | `:connection_id` | `self.object_id` |
233
233
 
234
234
  INFO. The adapters will add their own data as well.
235
235
 
@@ -1347,8 +1347,8 @@ config.assets.digest = true
1347
1347
 
1348
1348
  Rails 4 no longer sets default config values for Sprockets in `test.rb`, so
1349
1349
  `test.rb` now requires Sprockets configuration. The old defaults in the test
1350
- environment are: `config.assets.compile = true`, `config.assets.compress =
1351
- false`, `config.assets.debug = false` and `config.assets.digest = false`.
1350
+ environment are: `config.assets.compile = true`, `config.assets.compress = false`,
1351
+ `config.assets.debug = false` and `config.assets.digest = false`.
1352
1352
 
1353
1353
  The following should also be added to `Gemfile`:
1354
1354
 
@@ -1532,8 +1532,6 @@ Controls what happens to the associated objects when their owner is destroyed:
1532
1532
  * `:restrict_with_exception` causes an exception to be raised if there are any associated records
1533
1533
  * `:restrict_with_error` causes an error to be added to the owner if there are any associated objects
1534
1534
 
1535
- NOTE: This option is ignored when you use the `:through` option on the association.
1536
-
1537
1535
  ##### `:foreign_key`
1538
1536
 
1539
1537
  By convention, Rails assumes that the column used to hold the foreign key on the other model is the name of this model with the suffix `_id` added. The `:foreign_key` option lets you set the name of the foreign key directly:
@@ -61,7 +61,7 @@ With no further work, `rails server` will run our new shiny Rails app:
61
61
  $ cd commandsapp
62
62
  $ bin/rails server
63
63
  => Booting WEBrick
64
- => Rails 4.2.0 application starting in development on http://0.0.0.0:3000
64
+ => Rails 4.2.0 application starting in development on http://localhost:3000
65
65
  => Call with -d to detach
66
66
  => Ctrl-C to shutdown server
67
67
  [2013-08-07 02:00:01] INFO WEBrick 1.3.1
@@ -79,7 +79,7 @@ The server can be run on a different port using the `-p` option. The default dev
79
79
  $ bin/rails server -e production -p 4000
80
80
  ```
81
81
 
82
- 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.
82
+ The `-b` option binds Rails to the specified IP, by default it is localhost. You can run a server as a daemon by passing a `-d` option.
83
83
 
84
84
  ### `rails generate`
85
85
 
@@ -368,8 +368,7 @@ Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'mak
368
368
 
369
369
  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.
370
370
 
371
- To get the full backtrace for running rake task you can pass the option
372
- ```--trace``` to command line, for example ```rake db:create --trace```.
371
+ To get the full backtrace for running rake task you can pass the option ```--trace``` to command line, for example ```rake db:create --trace```.
373
372
 
374
373
  ```bash
375
374
  $ bin/rake --tasks
@@ -394,16 +393,11 @@ INFO: You can also use ```rake -T``` to get the list of tasks.
394
393
  ```bash
395
394
  $ bin/rake about
396
395
  About your application's environment
396
+ Rails version 4.2.0
397
397
  Ruby version 1.9.3 (x86_64-linux)
398
398
  RubyGems version 1.3.6
399
399
  Rack version 1.3
400
- Rails version 4.2.0
401
400
  JavaScript Runtime Node.js (V8)
402
- Active Record version 4.2.0
403
- Action Pack version 4.2.0
404
- Action View version 4.2.0
405
- Action Mailer version 4.2.0
406
- Active Support version 4.2.0
407
401
  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
408
402
  Application root /home/foobar/commandsapp
409
403
  Environment development
@@ -413,10 +407,7 @@ Database schema version 20110805173523
413
407
 
414
408
  ### `assets`
415
409
 
416
- You can precompile the assets in `app/assets` using `rake assets:precompile`,
417
- and remove older compiled assets using `rake assets:clean`. The `assets:clean`
418
- task allows for rolling deploys that may still be linking to an old asset while
419
- the new assets are being built.
410
+ You can precompile the assets in `app/assets` using `rake assets:precompile`, and remove older compiled assets using `rake assets:clean`. The `assets:clean` task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
420
411
 
421
412
  If you want to clear `public/assets` completely, you can use `rake assets:clobber`.
422
413
 
@@ -503,7 +494,7 @@ Rails comes with a test suite called Minitest. Rails owes its stability to the u
503
494
 
504
495
  ### `tmp`
505
496
 
506
- 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.
497
+ 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 sessions), process id files, and cached actions.
507
498
 
508
499
  The `tmp:` namespaced tasks will help you clear and create the `Rails.root/tmp` directory:
509
500