rails 4.1.4 → 4.2.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +12 -10
  3. data/guides/CHANGELOG.md +87 -15
  4. data/guides/Rakefile +21 -6
  5. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  6. data/guides/assets/javascripts/guides.js +6 -0
  7. data/guides/assets/stylesheets/main.css +4 -1
  8. data/guides/bug_report_templates/action_controller_gem.rb +3 -3
  9. data/guides/bug_report_templates/action_controller_master.rb +3 -2
  10. data/guides/bug_report_templates/active_record_gem.rb +1 -1
  11. data/guides/bug_report_templates/generic_gem.rb +15 -0
  12. data/guides/bug_report_templates/generic_master.rb +26 -0
  13. data/guides/rails_guides/helpers.rb +1 -1
  14. data/guides/rails_guides/levenshtein.rb +27 -21
  15. data/guides/rails_guides/markdown/renderer.rb +1 -1
  16. data/guides/rails_guides/markdown.rb +11 -7
  17. data/guides/rails_guides.rb +2 -2
  18. data/guides/source/2_2_release_notes.md +1 -1
  19. data/guides/source/2_3_release_notes.md +4 -4
  20. data/guides/source/3_0_release_notes.md +8 -8
  21. data/guides/source/3_1_release_notes.md +6 -3
  22. data/guides/source/3_2_release_notes.md +6 -3
  23. data/guides/source/4_0_release_notes.md +6 -3
  24. data/guides/source/4_1_release_notes.md +10 -11
  25. data/guides/source/4_2_release_notes.md +877 -0
  26. data/guides/source/_license.html.erb +1 -1
  27. data/guides/source/_welcome.html.erb +6 -8
  28. data/guides/source/action_controller_overview.md +28 -11
  29. data/guides/source/action_mailer_basics.md +97 -29
  30. data/guides/source/action_view_overview.md +142 -191
  31. data/guides/source/active_job_basics.md +339 -0
  32. data/guides/source/active_model_basics.md +371 -17
  33. data/guides/source/active_record_basics.md +25 -24
  34. data/guides/source/active_record_callbacks.md +12 -9
  35. data/guides/source/{migrations.md → active_record_migrations.md} +135 -226
  36. data/guides/source/active_record_postgresql.md +433 -0
  37. data/guides/source/active_record_querying.md +270 -262
  38. data/guides/source/active_record_validations.md +24 -14
  39. data/guides/source/active_support_core_extensions.md +115 -123
  40. data/guides/source/active_support_instrumentation.md +10 -18
  41. data/guides/source/api_documentation_guidelines.md +63 -17
  42. data/guides/source/asset_pipeline.md +266 -125
  43. data/guides/source/association_basics.md +96 -80
  44. data/guides/source/autoloading_and_reloading_constants.md +1311 -0
  45. data/guides/source/caching_with_rails.md +32 -7
  46. data/guides/source/command_line.md +52 -30
  47. data/guides/source/configuring.md +161 -33
  48. data/guides/source/contributing_to_ruby_on_rails.md +198 -114
  49. data/guides/source/credits.html.erb +2 -2
  50. data/guides/source/debugging_rails_applications.md +448 -294
  51. data/guides/source/development_dependencies_install.md +47 -36
  52. data/guides/source/documents.yaml +19 -7
  53. data/guides/source/engines.md +217 -196
  54. data/guides/source/form_helpers.md +79 -56
  55. data/guides/source/generators.md +24 -11
  56. data/guides/source/getting_started.md +361 -222
  57. data/guides/source/i18n.md +113 -69
  58. data/guides/source/index.html.erb +1 -0
  59. data/guides/source/initialization.md +110 -63
  60. data/guides/source/layout.html.erb +5 -11
  61. data/guides/source/layouts_and_rendering.md +26 -26
  62. data/guides/source/maintenance_policy.md +26 -4
  63. data/guides/source/nested_model_forms.md +7 -4
  64. data/guides/source/plugins.md +27 -27
  65. data/guides/source/rails_application_templates.md +21 -3
  66. data/guides/source/rails_on_rack.md +12 -10
  67. data/guides/source/routing.md +115 -75
  68. data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
  69. data/guides/source/security.md +41 -35
  70. data/guides/source/testing.md +199 -119
  71. data/guides/source/upgrading_ruby_on_rails.md +319 -32
  72. data/guides/source/working_with_javascript_in_rails.md +19 -17
  73. data/guides/w3c_validator.rb +2 -0
  74. metadata +42 -95
  75. data/guides/code/getting_started/Gemfile +0 -40
  76. data/guides/code/getting_started/Gemfile.lock +0 -125
  77. data/guides/code/getting_started/README.rdoc +0 -28
  78. data/guides/code/getting_started/Rakefile +0 -6
  79. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  80. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  81. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  82. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  83. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  84. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  85. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  86. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  87. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  88. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  89. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  90. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  91. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  92. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  93. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  94. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  95. data/guides/code/getting_started/app/models/comment.rb +0 -3
  96. data/guides/code/getting_started/app/models/post.rb +0 -7
  97. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  98. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  99. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  100. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  101. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  102. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  103. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  104. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  105. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  106. data/guides/code/getting_started/bin/bundle +0 -4
  107. data/guides/code/getting_started/bin/rails +0 -4
  108. data/guides/code/getting_started/bin/rake +0 -4
  109. data/guides/code/getting_started/config/application.rb +0 -18
  110. data/guides/code/getting_started/config/boot.rb +0 -4
  111. data/guides/code/getting_started/config/database.yml +0 -25
  112. data/guides/code/getting_started/config/environment.rb +0 -5
  113. data/guides/code/getting_started/config/environments/development.rb +0 -30
  114. data/guides/code/getting_started/config/environments/production.rb +0 -80
  115. data/guides/code/getting_started/config/environments/test.rb +0 -36
  116. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  117. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  118. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  119. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  120. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  121. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  122. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  123. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  124. data/guides/code/getting_started/config/locales/en.yml +0 -23
  125. data/guides/code/getting_started/config/routes.rb +0 -7
  126. data/guides/code/getting_started/config.ru +0 -4
  127. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  128. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  129. data/guides/code/getting_started/db/schema.rb +0 -33
  130. data/guides/code/getting_started/db/seeds.rb +0 -7
  131. data/guides/code/getting_started/public/404.html +0 -60
  132. data/guides/code/getting_started/public/422.html +0 -60
  133. data/guides/code/getting_started/public/500.html +0 -59
  134. data/guides/code/getting_started/public/favicon.ico +0 -0
  135. data/guides/code/getting_started/public/robots.txt +0 -5
  136. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  137. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  138. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  139. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  140. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  141. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  142. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  143. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  144. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  145. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  146. data/guides/code/getting_started/test/test_helper.rb +0 -12
@@ -1,2 +1,2 @@
1
- <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
1
+ <p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p>
2
2
  <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
@@ -10,16 +10,14 @@
10
10
  </p>
11
11
  <% else %>
12
12
  <p>
13
- These are the new guides for Rails 4.1 based on <a href="https://github.com/rails/rails/tree/<%= @version %>"><%= @version %></a>.
13
+ These are the new guides for Rails 4.2 based on <a href="https://github.com/rails/rails/tree/<%= @version %>"><%= @version %></a>.
14
14
  These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together.
15
15
  </p>
16
16
  <% end %>
17
17
  <p>
18
- The guides for Rails 4.0.x are available at <a href="http://guides.rubyonrails.org/v4.0.6/">http://guides.rubyonrails.org/v4.0.6/</a>.
19
- </p>
20
- <p>
21
- The guides for Rails 3.2.x are available at <a href="http://guides.rubyonrails.org/v3.2.18/">http://guides.rubyonrails.org/v3.2.18/</a>.
22
- </p>
23
- <p>
24
- The guides for Rails 2.3.x are available at <a href="http://guides.rubyonrails.org/v2.3.11/">http://guides.rubyonrails.org/v2.3.11/</a>.
18
+ The guides for earlier releases:
19
+ <a href="http://guides.rubyonrails.org/v4.1/">Rails 4.1</a>,
20
+ <a href="http://guides.rubyonrails.org/v4.0/">Rails 4.0</a>,
21
+ <a href="http://guides.rubyonrails.org/v3.2/">Rails 3.2</a>, and
22
+ <a href="http://guides.rubyonrails.org/v2.3/">Rails 2.3</a>.
25
23
  </p>
@@ -34,7 +34,7 @@ The naming convention of controllers in Rails favors pluralization of the last w
34
34
 
35
35
  Following this convention will allow you to use the default route generators (e.g. `resources`, etc) without needing to qualify each `:path` or `:controller`, and keeps URL and path helpers' usage consistent throughout your application. See [Layouts & Rendering Guide](layouts_and_rendering.html) for more details.
36
36
 
37
- NOTE: The controller naming convention differs from the naming convention of models, which expected to be named in singular form.
37
+ NOTE: The controller naming convention differs from the naming convention of models, which are expected to be named in singular form.
38
38
 
39
39
 
40
40
  Methods and Actions
@@ -260,7 +260,7 @@ used:
260
260
  params.require(:log_entry).permit!
261
261
  ```
262
262
 
263
- This will mark the `:log_entry` parameters hash and any subhash of it
263
+ This will mark the `:log_entry` parameters hash and any sub-hash of it
264
264
  permitted. Extreme care should be taken when using `permit!` as it
265
265
  will allow all current and future model attributes to be
266
266
  mass-assigned.
@@ -364,33 +364,48 @@ If you need a different session storage mechanism, you can change it in the `con
364
364
  # Use the database for sessions instead of the cookie-based default,
365
365
  # which shouldn't be used to store highly confidential information
366
366
  # (create the session table with "rails g active_record:session_migration")
367
- # YourApp::Application.config.session_store :active_record_store
367
+ # Rails.application.config.session_store :active_record_store
368
368
  ```
369
369
 
370
370
  Rails sets up a session key (the name of the cookie) when signing the session data. These can also be changed in `config/initializers/session_store.rb`:
371
371
 
372
372
  ```ruby
373
373
  # Be sure to restart your server when you modify this file.
374
- YourApp::Application.config.session_store :cookie_store, key: '_your_app_session'
374
+ Rails.application.config.session_store :cookie_store, key: '_your_app_session'
375
375
  ```
376
376
 
377
377
  You can also pass a `:domain` key and specify the domain name for the cookie:
378
378
 
379
379
  ```ruby
380
380
  # Be sure to restart your server when you modify this file.
381
- YourApp::Application.config.session_store :cookie_store, key: '_your_app_session', domain: ".example.com"
381
+ Rails.application.config.session_store :cookie_store, key: '_your_app_session', domain: ".example.com"
382
382
  ```
383
383
 
384
- Rails sets up (for the CookieStore) a secret key used for signing the session data. This can be changed in `config/initializers/secret_token.rb`
384
+ Rails sets up (for the CookieStore) a secret key used for signing the session data. This can be changed in `config/secrets.yml`
385
385
 
386
386
  ```ruby
387
387
  # Be sure to restart your server when you modify this file.
388
388
 
389
- # Your secret key for verifying the integrity of signed cookies.
389
+ # Your secret key is used for verifying the integrity of signed cookies.
390
390
  # If you change this key, all old signed cookies will become invalid!
391
+
391
392
  # Make sure the secret is at least 30 characters and all random,
392
393
  # no regular words or you'll be exposed to dictionary attacks.
393
- YourApp::Application.config.secret_key_base = '49d3f3de9ed86c74b94ad6bd0...'
394
+ # You can use `rake secret` to generate a secure secret key.
395
+
396
+ # Make sure the secrets in this file are kept private
397
+ # if you're sharing your code publicly.
398
+
399
+ development:
400
+ secret_key_base: a75d...
401
+
402
+ test:
403
+ secret_key_base: 492f...
404
+
405
+ # Do not keep production secrets in the repository,
406
+ # instead read values from the environment.
407
+ production:
408
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
394
409
  ```
395
410
 
396
411
  NOTE: Changing the secret when using the `CookieStore` will invalidate all existing sessions.
@@ -720,7 +735,7 @@ You can choose not to yield and build the response yourself, in which case the a
720
735
 
721
736
  While the most common way to use filters is by creating private methods and using *_action to add them, there are two other ways to do the same thing.
722
737
 
723
- The first is to use a block directly with the *_action methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block:
738
+ The first is to use a block directly with the *\_action methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block:
724
739
 
725
740
  ```ruby
726
741
  class ApplicationController < ActionController::Base
@@ -1063,7 +1078,7 @@ Rails keeps a log file for each environment in the `log` folder. These are extre
1063
1078
 
1064
1079
  ### Parameters Filtering
1065
1080
 
1066
- You can filter certain request parameters from your log files by appending them to `config.filter_parameters` in the application configuration. These parameters will be marked [FILTERED] in the log.
1081
+ You can filter out sensitive request parameters from your log files by appending them to `config.filter_parameters` in the application configuration. These parameters will be marked [FILTERED] in the log.
1067
1082
 
1068
1083
  ```ruby
1069
1084
  config.filter_parameters << :password
@@ -1071,7 +1086,7 @@ config.filter_parameters << :password
1071
1086
 
1072
1087
  ### Redirects Filtering
1073
1088
 
1074
- Sometimes it's desirable to filter out from log files some sensible locations your application is redirecting to.
1089
+ Sometimes it's desirable to filter out from log files some sensitive locations your application is redirecting to.
1075
1090
  You can do that by using the `config.filter_redirect` configuration option:
1076
1091
 
1077
1092
  ```ruby
@@ -1149,6 +1164,8 @@ class ClientsController < ApplicationController
1149
1164
  end
1150
1165
  ```
1151
1166
 
1167
+ WARNING: You shouldn't do `rescue_from Exception` or `rescue_from StandardError` unless you have a particular reason as it will cause serious side-effects (e.g. you won't be able to see exception details and tracebacks during development).
1168
+
1152
1169
  NOTE: Certain exceptions are only rescuable from the `ApplicationController` class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's [article](http://m.onkey.org/2008/7/20/rescue-from-dispatching) on the subject for more information.
1153
1170
 
1154
1171
  Force HTTPS protocol
@@ -17,7 +17,10 @@ After reading this guide, you will know:
17
17
  Introduction
18
18
  ------------
19
19
 
20
- Action Mailer allows you to send emails from your application using mailer classes and views. Mailers work very similarly to controllers. They inherit from `ActionMailer::Base` and live in `app/mailers`, and they have associated views that appear in `app/views`.
20
+ Action Mailer allows you to send emails from your application using mailer classes
21
+ and views. Mailers work very similarly to controllers. They inherit from
22
+ `ActionMailer::Base` and live in `app/mailers`, and they have associated views
23
+ that appear in `app/views`.
21
24
 
22
25
  Sending Emails
23
26
  --------------
@@ -32,10 +35,26 @@ views.
32
35
  ```bash
33
36
  $ bin/rails generate mailer UserMailer
34
37
  create app/mailers/user_mailer.rb
38
+ create app/mailers/application_mailer.rb
35
39
  invoke erb
36
40
  create app/views/user_mailer
41
+ create app/views/layouts/mailer.text.erb
42
+ create app/views/layouts/mailer.html.erb
37
43
  invoke test_unit
38
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: "from@example.com"
52
+ layout 'mailer'
53
+ end
54
+
55
+ # app/mailers/user_mailer.rb
56
+ class UserMailer < ApplicationMailer
57
+ end
39
58
  ```
40
59
 
41
60
  As you can see, you can generate mailers just like you use other generators with
@@ -60,8 +79,7 @@ delivered via email.
60
79
  `app/mailers/user_mailer.rb` contains an empty mailer:
61
80
 
62
81
  ```ruby
63
- class UserMailer < ActionMailer::Base
64
- default from: 'from@example.com'
82
+ class UserMailer < ApplicationMailer
65
83
  end
66
84
  ```
67
85
 
@@ -69,7 +87,7 @@ Let's add a method called `welcome_email`, that will send an email to the user's
69
87
  registered email address:
70
88
 
71
89
  ```ruby
72
- class UserMailer < ActionMailer::Base
90
+ class UserMailer < ApplicationMailer
73
91
  default from: 'notifications@example.com'
74
92
 
75
93
  def welcome_email(user)
@@ -84,8 +102,11 @@ Here is a quick explanation of the items presented in the preceding method. For
84
102
  a full list of all available options, please have a look further down at the
85
103
  Complete List of Action Mailer user-settable attributes section.
86
104
 
87
- * `default Hash` - This is a hash of default values for any email you send from this mailer. In this case we are setting the `:from` header to a value for all messages in this class. This can be overridden on a per-email basis.
88
- * `mail` - The actual email message, we are passing the `:to` and `:subject` headers in.
105
+ * `default Hash` - This is a hash of default values for any email you send from
106
+ this mailer. In this case we are setting the `:from` header to a value for all
107
+ messages in this class. This can be overridden on a per-email basis.
108
+ * `mail` - The actual email message, we are passing the `:to` and `:subject`
109
+ headers in.
89
110
 
90
111
  Just like controllers, any instance variables we define in the method become
91
112
  available for use in the views.
@@ -151,9 +172,12 @@ $ bin/rake db:migrate
151
172
  ```
152
173
 
153
174
  Now that we have a user model to play with, we will just edit the
154
- `app/controllers/users_controller.rb` make it instruct the UserMailer to deliver
175
+ `app/controllers/users_controller.rb` make it instruct the `UserMailer` to deliver
155
176
  an email to the newly created user by editing the create action and inserting a
156
- call to `UserMailer.welcome_email` right after the user is successfully saved:
177
+ call to `UserMailer.welcome_email` right after the user is successfully saved.
178
+
179
+ Action Mailer is nicely integrated with Active Job so you can send emails outside
180
+ of the request-response cycle, so the user doesn't have to wait on it:
157
181
 
158
182
  ```ruby
159
183
  class UsersController < ApplicationController
@@ -165,7 +189,7 @@ class UsersController < ApplicationController
165
189
  respond_to do |format|
166
190
  if @user.save
167
191
  # Tell the UserMailer to send a welcome email after save
168
- UserMailer.welcome_email(@user).deliver
192
+ UserMailer.welcome_email(@user).deliver_later
169
193
 
170
194
  format.html { redirect_to(@user, notice: 'User was successfully created.') }
171
195
  format.json { render json: @user, status: :created, location: @user }
@@ -178,8 +202,29 @@ class UsersController < ApplicationController
178
202
  end
179
203
  ```
180
204
 
181
- The method `welcome_email` returns a `Mail::Message` object which can then just
182
- be told `deliver` to send itself out.
205
+ NOTE: Active Job's default behavior is to execute jobs ':inline'. So, you can use
206
+ `deliver_later` now to send emails, and when you later decide to start sending
207
+ them from a background job, you'll only need to set up Active Job to use a queueing
208
+ backend (Sidekiq, Resque, etc).
209
+
210
+ If you want to send emails right away (from a cronjob for example) just call
211
+ `deliver_now`:
212
+
213
+ ```ruby
214
+ class SendWeeklySummary
215
+ def run
216
+ User.find_each do |user|
217
+ UserMailer.weekly_summary(user).deliver_now
218
+ end
219
+ end
220
+ end
221
+ ```
222
+
223
+ The method `welcome_email` returns a `ActionMailer::MessageDelivery` object which
224
+ can then just be told `deliver_now` or `deliver_later` to send itself out. The
225
+ `ActionMailer::MessageDelivery` object is just a wrapper around a `Mail::Message`. If
226
+ you want to inspect, alter or do anything else with the `Mail::Message` object you can
227
+ access it with the `message` method on the `ActionMailer::MessageDelivery` object.
183
228
 
184
229
  ### Auto encoding header values
185
230
 
@@ -230,9 +275,11 @@ different, encode your content and pass in the encoded content and encoding in a
230
275
 
231
276
  ```ruby
232
277
  encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
233
- attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
234
- encoding: 'SpecialEncoding',
235
- content: encoded_content }
278
+ attachments['filename.jpg'] = {
279
+ mime_type: 'application/x-gzip',
280
+ encoding: 'SpecialEncoding',
281
+ content: encoded_content
282
+ }
236
283
  ```
237
284
 
238
285
  NOTE: If you specify an encoding, Mail will assume that your content is already
@@ -266,8 +313,7 @@ Action Mailer 3.0 makes inline attachments, which involved a lot of hacking in p
266
313
  ```html+erb
267
314
  <p>Hello there, this is our image</p>
268
315
 
269
- <%= image_tag attachments['image.jpg'].url, alt: 'My Photo',
270
- class: 'photos' %>
316
+ <%= image_tag attachments['image.jpg'].url, alt: 'My Photo', class: 'photos' %>
271
317
  ```
272
318
 
273
319
  #### Sending Email To Multiple Recipients
@@ -301,7 +347,7 @@ email address in the format `"Full Name <email>"`.
301
347
  ```ruby
302
348
  def welcome_email(user)
303
349
  @user = user
304
- email_with_name = "#{@user.name} <#{@user.email}>"
350
+ email_with_name = %("#{@user.name}" <#{@user.email}>)
305
351
  mail(to: email_with_name, subject: 'Welcome to My Awesome Site')
306
352
  end
307
353
  ```
@@ -317,7 +363,7 @@ for the HTML version and `welcome_email.text.erb` for the plain text version.
317
363
  To change the default mailer view for your action you do something like:
318
364
 
319
365
  ```ruby
320
- class UserMailer < ActionMailer::Base
366
+ class UserMailer < ApplicationMailer
321
367
  default from: 'notifications@example.com'
322
368
 
323
369
  def welcome_email(user)
@@ -339,7 +385,7 @@ If you want more flexibility you can also pass a block and render specific
339
385
  templates or even render inline or text without using a template file:
340
386
 
341
387
  ```ruby
342
- class UserMailer < ActionMailer::Base
388
+ class UserMailer < ApplicationMailer
343
389
  default from: 'notifications@example.com'
344
390
 
345
391
  def welcome_email(user)
@@ -369,7 +415,7 @@ layout.
369
415
  In order to use a different file, call `layout` in your mailer:
370
416
 
371
417
  ```ruby
372
- class UserMailer < ActionMailer::Base
418
+ class UserMailer < ApplicationMailer
373
419
  layout 'awesome' # use awesome.(html|text).erb as the layout
374
420
  end
375
421
  ```
@@ -381,7 +427,7 @@ You can also pass in a `layout: 'layout_name'` option to the render call inside
381
427
  the format block to specify different layouts for different formats:
382
428
 
383
429
  ```ruby
384
- class UserMailer < ActionMailer::Base
430
+ class UserMailer < ApplicationMailer
385
431
  def welcome_email(user)
386
432
  mail(to: user.email) do |format|
387
433
  format.html { render layout: 'my_layout' }
@@ -406,6 +452,22 @@ globally in `config/application.rb`:
406
452
  config.action_mailer.default_url_options = { host: 'example.com' }
407
453
  ```
408
454
 
455
+ Because of this behavior you cannot use any of the `*_path` helpers inside of
456
+ an email. Instead you will need to use the associated `*_url` helper. For example
457
+ instead of using
458
+
459
+ ```
460
+ <%= link_to 'welcome', welcome_path %>
461
+ ```
462
+
463
+ You will need to use:
464
+
465
+ ```
466
+ <%= link_to 'welcome', welcome_url %>
467
+ ```
468
+
469
+ By using the full URL, your links will now work in your emails.
470
+
409
471
  #### generating URLs with `url_for`
410
472
 
411
473
  You need to pass the `only_path: false` option when using `url_for`. This will
@@ -445,6 +507,9 @@ url helper.
445
507
  <%= user_url(@user, host: 'example.com') %>
446
508
  ```
447
509
 
510
+ NOTE: non-`GET` links require [jQuery UJS](https://github.com/rails/jquery-ujs)
511
+ and won't work in mailer templates. They will result in normal `GET` requests.
512
+
448
513
  ### Sending Multipart Emails
449
514
 
450
515
  Action Mailer will automatically send multipart emails if you have different
@@ -463,7 +528,7 @@ while delivering emails, you can do this using `delivery_method_options` in the
463
528
  mailer action.
464
529
 
465
530
  ```ruby
466
- class UserMailer < ActionMailer::Base
531
+ class UserMailer < ApplicationMailer
467
532
  def welcome_email(user, company)
468
533
  @user = user
469
534
  @url = user_url(@user)
@@ -485,7 +550,7 @@ option. In such cases don't forget to add the `:content_type` option. Rails
485
550
  will default to `text/plain` otherwise.
486
551
 
487
552
  ```ruby
488
- class UserMailer < ActionMailer::Base
553
+ class UserMailer < ApplicationMailer
489
554
  def welcome_email(user, email_body)
490
555
  mail(to: user.email,
491
556
  body: email_body,
@@ -515,7 +580,7 @@ mailer, and pass the email object to the mailer `receive` instance
515
580
  method. Here's an example:
516
581
 
517
582
  ```ruby
518
- class UserMailer < ActionMailer::Base
583
+ class UserMailer < ApplicationMailer
519
584
  def receive(email)
520
585
  page = Page.find_by(address: email.to.first)
521
586
  page.emails.create(
@@ -551,7 +616,7 @@ Action Mailer allows for you to specify a `before_action`, `after_action` and
551
616
  using instance variables set in your mailer action.
552
617
 
553
618
  ```ruby
554
- class UserMailer < ActionMailer::Base
619
+ class UserMailer < ApplicationMailer
555
620
  after_action :set_delivery_options,
556
621
  :prevent_delivery_to_guests,
557
622
  :set_business_headers
@@ -608,7 +673,7 @@ files (environment.rb, production.rb, etc...)
608
673
  | Configuration | Description |
609
674
  |---------------|-------------|
610
675
  |`logger`|Generates information on the mailing run if available. Can be set to `nil` for no logging. Compatible with both Ruby's own `Logger` and `Log4r` loggers.|
611
- |`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default "localhost" setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain`, `:login`, `:cram_md5`.</li><li>`:enable_starttls_auto` - Set this to `false` if there is a problem with your server certificate that you cannot resolve.</li></ul>|
676
+ |`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default `"localhost"` setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain` (will send the password in the clear), `:login` (will send password Base64 encoded) or `:cram_md5` (combines a Challenge/Response mechanism to exchange information and a cryptographic Message Digest 5 algorithm to hash important information)</li><li>`:enable_starttls_auto` - Detects if STARTTLS is enabled in your SMTP server and starts to use it. Defaults to `true`.</li><li>`:openssl_verify_mode` - When using TLS, you can set how OpenSSL checks the certificate. This is really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name of an OpenSSL verify constant ('none', 'peer', 'client_once', 'fail_if_no_peer_cert') or directly the constant (`OpenSSL::SSL::VERIFY_NONE`, `OpenSSL::SSL::VERIFY_PEER`, ...).</li></ul>|
612
677
  |`sendmail_settings`|Allows you to override options for the `:sendmail` delivery method.<ul><li>`:location` - The location of the sendmail executable. Defaults to `/usr/sbin/sendmail`.</li><li>`:arguments` - The command line arguments to be passed to sendmail. Defaults to `-i -t`.</li></ul>|
613
678
  |`raise_delivery_errors`|Whether or not errors should be raised if the email fails to be delivered. This only works if the external email server is configured for immediate delivery.|
614
679
  |`delivery_method`|Defines a delivery method. Possible values are:<ul><li>`:smtp` (default), can be configured by using `config.action_mailer.smtp_settings`.</li><li>`:sendmail`, can be configured by using `config.action_mailer.sendmail_settings`.</li><li>`:file`: save emails to files; can be configured by using `config.action_mailer.file_settings`.</li><li>`:test`: save emails to `ActionMailer::Base.deliveries` array.</li></ul>See [API docs](http://api.rubyonrails.org/classes/ActionMailer/Base.html) for more info.|
@@ -617,7 +682,7 @@ files (environment.rb, production.rb, etc...)
617
682
  |`default_options`|Allows you to set default values for the `mail` method options (`:from`, `:reply_to`, etc.).|
618
683
 
619
684
  For a complete writeup of possible configurations see the
620
- [Action Mailer section](configuring.html#configuring-action-mailer) in
685
+ [Configuring Action Mailer](configuring.html#configuring-action-mailer) in
621
686
  our Configuring Rails Applications guide.
622
687
 
623
688
  ### Example Action Mailer Configuration
@@ -662,6 +727,7 @@ You can find detailed instructions on how to test your mailers in the
662
727
 
663
728
  Intercepting Emails
664
729
  -------------------
730
+
665
731
  There are situations where you need to edit an email before it's
666
732
  delivered. Fortunately Action Mailer provides hooks to intercept every
667
733
  email. You can register an interceptor to make modifications to mail messages
@@ -680,10 +746,12 @@ Mailer framework. You can do this in an initializer file
680
746
  `config/initializers/sandbox_email_interceptor.rb`
681
747
 
682
748
  ```ruby
683
- ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) if Rails.env.staging?
749
+ if Rails.env.staging?
750
+ ActionMailer::Base.register_interceptor(SandboxEmailInterceptor)
751
+ end
684
752
  ```
685
753
 
686
754
  NOTE: The example above uses a custom environment called "staging" for a
687
755
  production like server but for testing purposes. You can read
688
- [Creating Rails environments](./configuring.html#creating-rails-environments)
756
+ [Creating Rails environments](configuring.html#creating-rails-environments)
689
757
  for more information about custom Rails environments.