rails 4.2.0.beta4 → 4.2.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/guides/Rakefile +3 -1
- data/guides/bug_report_templates/action_controller_gem.rb +2 -2
- data/guides/bug_report_templates/action_controller_master.rb +2 -2
- data/guides/source/3_0_release_notes.md +2 -2
- data/guides/source/4_1_release_notes.md +1 -1
- data/guides/source/4_2_release_notes.md +250 -225
- data/guides/source/_welcome.html.erb +1 -1
- data/guides/source/action_controller_overview.md +6 -6
- data/guides/source/action_mailer_basics.md +26 -11
- data/guides/source/action_view_overview.md +0 -1
- data/guides/source/active_job_basics.md +29 -23
- data/guides/source/active_record_postgresql.md +2 -7
- data/guides/source/active_record_validations.md +1 -0
- data/guides/source/active_support_core_extensions.md +1 -1
- data/guides/source/active_support_instrumentation.md +5 -5
- data/guides/source/asset_pipeline.md +2 -2
- data/guides/source/association_basics.md +0 -2
- data/guides/source/command_line.md +6 -15
- data/guides/source/configuring.md +4 -4
- data/guides/source/documents.yaml +0 -1
- data/guides/source/engines.md +26 -15
- data/guides/source/form_helpers.md +10 -2
- data/guides/source/getting_started.md +9 -9
- data/guides/source/rails_on_rack.md +2 -2
- data/guides/source/ruby_on_rails_guides_guidelines.md +1 -0
- data/guides/source/security.md +1 -1
- data/guides/source/testing.md +80 -13
- data/guides/source/upgrading_ruby_on_rails.md +23 -20
- metadata +29 -229
- data/guides/output/2_2_release_notes.html +0 -724
- data/guides/output/2_3_release_notes.html +0 -870
- data/guides/output/3_0_release_notes.html +0 -773
- data/guides/output/3_1_release_notes.html +0 -740
- data/guides/output/3_2_release_notes.html +0 -797
- data/guides/output/4_0_release_notes.html +0 -523
- data/guides/output/4_1_release_notes.html +0 -806
- data/guides/output/4_2_release_notes.html +0 -728
- data/guides/output/Gemfile +0 -6
- data/guides/output/_license.html +0 -226
- data/guides/output/_welcome.html +0 -233
- data/guides/output/action_controller_overview.html +0 -1335
- data/guides/output/action_mailer_basics.html +0 -928
- data/guides/output/action_view_overview.html +0 -1509
- data/guides/output/active_job_basics.html +0 -546
- data/guides/output/active_model_basics.html +0 -438
- data/guides/output/active_record_basics.html +0 -594
- data/guides/output/active_record_callbacks.html +0 -592
- data/guides/output/active_record_migrations.html +0 -1123
- data/guides/output/active_record_postgresql.html +0 -675
- data/guides/output/active_record_querying.html +0 -1796
- data/guides/output/active_record_validations.html +0 -1301
- data/guides/output/active_support_core_extensions.html +0 -3450
- data/guides/output/active_support_instrumentation.html +0 -1121
- data/guides/output/api_documentation_guidelines.html +0 -498
- data/guides/output/asset_pipeline.html +0 -1167
- data/guides/output/association_basics.html +0 -2086
- data/guides/output/caching_with_rails.html +0 -553
- data/guides/output/command_line.html +0 -791
- data/guides/output/configuring.html +0 -1055
- data/guides/output/contributing_to_ruby_on_rails.html +0 -657
- data/guides/output/credits.html +0 -284
- data/guides/output/debugging_rails_applications.html +0 -1014
- data/guides/output/development_dependencies_install.html +0 -478
- data/guides/output/engines.html +0 -1438
- data/guides/output/form_helpers.html +0 -1074
- data/guides/output/generators.html +0 -838
- data/guides/output/getting_started.html +0 -2092
- data/guides/output/i18n.html +0 -1198
- data/guides/output/images/akshaysurve.jpg +0 -0
- data/guides/output/images/belongs_to.png +0 -0
- data/guides/output/images/book_icon.gif +0 -0
- data/guides/output/images/bullet.gif +0 -0
- data/guides/output/images/chapters_icon.gif +0 -0
- data/guides/output/images/check_bullet.gif +0 -0
- data/guides/output/images/credits_pic_blank.gif +0 -0
- data/guides/output/images/csrf.png +0 -0
- data/guides/output/images/edge_badge.png +0 -0
- data/guides/output/images/favicon.ico +0 -0
- data/guides/output/images/feature_tile.gif +0 -0
- data/guides/output/images/footer_tile.gif +0 -0
- data/guides/output/images/fxn.png +0 -0
- data/guides/output/images/getting_started/article_with_comments.png +0 -0
- data/guides/output/images/getting_started/challenge.png +0 -0
- data/guides/output/images/getting_started/confirm_dialog.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
- data/guides/output/images/getting_started/form_with_errors.png +0 -0
- data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
- data/guides/output/images/getting_started/new_article.png +0 -0
- data/guides/output/images/getting_started/new_post.png +0 -0
- data/guides/output/images/getting_started/post_with_comments.png +0 -0
- data/guides/output/images/getting_started/rails_welcome.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
- data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
- data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
- data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
- data/guides/output/images/grey_bullet.gif +0 -0
- data/guides/output/images/habtm.png +0 -0
- data/guides/output/images/has_many.png +0 -0
- data/guides/output/images/has_many_through.png +0 -0
- data/guides/output/images/has_one.png +0 -0
- data/guides/output/images/has_one_through.png +0 -0
- data/guides/output/images/header_backdrop.png +0 -0
- data/guides/output/images/header_tile.gif +0 -0
- data/guides/output/images/i18n/demo_html_safe.png +0 -0
- data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translated_en.png +0 -0
- data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translation_missing.png +0 -0
- data/guides/output/images/i18n/demo_untranslated.png +0 -0
- data/guides/output/images/icons/README +0 -5
- data/guides/output/images/icons/callouts/1.png +0 -0
- data/guides/output/images/icons/callouts/10.png +0 -0
- data/guides/output/images/icons/callouts/11.png +0 -0
- data/guides/output/images/icons/callouts/12.png +0 -0
- data/guides/output/images/icons/callouts/13.png +0 -0
- data/guides/output/images/icons/callouts/14.png +0 -0
- data/guides/output/images/icons/callouts/15.png +0 -0
- data/guides/output/images/icons/callouts/2.png +0 -0
- data/guides/output/images/icons/callouts/3.png +0 -0
- data/guides/output/images/icons/callouts/4.png +0 -0
- data/guides/output/images/icons/callouts/5.png +0 -0
- data/guides/output/images/icons/callouts/6.png +0 -0
- data/guides/output/images/icons/callouts/7.png +0 -0
- data/guides/output/images/icons/callouts/8.png +0 -0
- data/guides/output/images/icons/callouts/9.png +0 -0
- data/guides/output/images/icons/caution.png +0 -0
- data/guides/output/images/icons/example.png +0 -0
- data/guides/output/images/icons/home.png +0 -0
- data/guides/output/images/icons/important.png +0 -0
- data/guides/output/images/icons/next.png +0 -0
- data/guides/output/images/icons/note.png +0 -0
- data/guides/output/images/icons/prev.png +0 -0
- data/guides/output/images/icons/tip.png +0 -0
- data/guides/output/images/icons/up.png +0 -0
- data/guides/output/images/icons/warning.png +0 -0
- data/guides/output/images/nav_arrow.gif +0 -0
- data/guides/output/images/oscardelben.jpg +0 -0
- data/guides/output/images/polymorphic.png +0 -0
- data/guides/output/images/radar.png +0 -0
- data/guides/output/images/rails4_features.png +0 -0
- data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
- data/guides/output/images/rails_guides_logo.gif +0 -0
- data/guides/output/images/rails_logo_remix.gif +0 -0
- data/guides/output/images/session_fixation.png +0 -0
- data/guides/output/images/tab_grey.gif +0 -0
- data/guides/output/images/tab_info.gif +0 -0
- data/guides/output/images/tab_note.gif +0 -0
- data/guides/output/images/tab_red.gif +0 -0
- data/guides/output/images/tab_yellow.gif +0 -0
- data/guides/output/images/tab_yellow.png +0 -0
- data/guides/output/images/vijaydev.jpg +0 -0
- data/guides/output/index.html +0 -354
- data/guides/output/initialization.html +0 -876
- data/guides/output/javascripts/guides.js +0 -59
- data/guides/output/javascripts/jquery.min.js +0 -4
- data/guides/output/javascripts/responsive-tables.js +0 -43
- data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
- data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
- data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
- data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
- data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
- data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
- data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
- data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
- data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
- data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
- data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
- data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
- data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
- data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
- data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
- data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
- data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
- data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
- data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
- data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
- data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
- data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
- data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
- data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
- data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
- data/guides/output/javascripts/syntaxhighlighter/shCore.js +0 -17
- data/guides/output/layout.html +0 -448
- data/guides/output/layouts_and_rendering.html +0 -1541
- data/guides/output/maintenance_policy.html +0 -257
- data/guides/output/migrations.html +0 -1360
- data/guides/output/nested_model_forms.html +0 -412
- data/guides/output/plugins.html +0 -644
- data/guides/output/rails_application_templates.html +0 -450
- data/guides/output/rails_on_rack.html +0 -547
- data/guides/output/routing.html +0 -1631
- data/guides/output/ruby_on_rails_guides_guidelines.html +0 -329
- data/guides/output/security.html +0 -935
- data/guides/output/stylesheets/fixes.css +0 -16
- data/guides/output/stylesheets/kindle.css +0 -11
- data/guides/output/stylesheets/main.css +0 -713
- data/guides/output/stylesheets/print.css +0 -52
- data/guides/output/stylesheets/reset.css +0 -43
- data/guides/output/stylesheets/responsive-tables.css +0 -50
- data/guides/output/stylesheets/style.css +0 -13
- data/guides/output/stylesheets/syntaxhighlighter/shCore.css +0 -226
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
- data/guides/output/testing.html +0 -1350
- data/guides/output/upgrading_ruby_on_rails.html +0 -1135
- data/guides/output/working_with_javascript_in_rails.html +0 -587
@@ -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.
|
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
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
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 <
|
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 <
|
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 <
|
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 <
|
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 <
|
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 <
|
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 <
|
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 <
|
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 <
|
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 <
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
###
|
107
|
+
### Setting the Backend
|
107
108
|
|
108
|
-
You can easily
|
109
|
+
You can easily set your queueing backend:
|
109
110
|
|
110
111
|
```ruby
|
111
|
-
#
|
112
|
-
|
113
|
-
|
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
|
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
|
176
|
-
option to
|
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
|
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
|
-
|
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/
|
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 # => "
|
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
|
|
@@ -225,11 +225,11 @@ Active Record
|
|
225
225
|
|
226
226
|
### sql.active_record
|
227
227
|
|
228
|
-
| Key
|
229
|
-
|
|
230
|
-
| `:sql`
|
231
|
-
| `:name`
|
232
|
-
| `:
|
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
|
-
|
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://
|
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
|
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
|
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
|
|