質問編集履歴
1
コードを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
rails チュートリアル11章のメイラーの部分をやっています。applicatoin_mailer.rbのdefault from: の部分を変えてもプレビューで反映されません
|
1
|
+
rails チュートリアル11章のメイラーの部分をやっています。applicatoin_mailer.rbのdefault from: の部分を変えてもプレビューで反映されませんでした。
|
2
|
-
|
3
|
-
> mailer生成
|
4
|
-
```
|
5
|
-
rails generate mailer UserMailer account_activation password_reset
|
6
|
-
```
|
7
|
-
|
8
2
|

|
9
3
|
> application_mailer.rb
|
10
4
|
```ruby
|
@@ -31,37 +25,47 @@
|
|
31
25
|
end
|
32
26
|
|
33
27
|
```
|
28
|
+
その後、user_mailer.rbで個別にfrom:で設定したところ、問題なく動作しました。
|
29
|
+
なぜdefault from: では反映されなかったのでしょうか?
|
30
|
+

|
34
|
-
>
|
31
|
+
> application_mailer.rb
|
35
32
|
```ruby
|
36
|
-
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
|
37
|
-
class
|
33
|
+
class ApplicationMailer < ActionMailer::Base
|
34
|
+
layout 'mailer'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
> user_mailer.rb
|
38
|
+
```ruby
|
39
|
+
class UserMailer < ApplicationMailer
|
38
40
|
|
39
|
-
# Preview this email at
|
40
|
-
#
|
41
|
+
# Subject can be set in your I18n file at config/locales/en.yml
|
42
|
+
# with the following lookup:
|
43
|
+
#
|
44
|
+
# en.user_mailer.account_activation.subject
|
45
|
+
#
|
41
|
-
def account_activation
|
46
|
+
def account_activation(user)
|
42
|
-
user =
|
47
|
+
@user = user
|
43
|
-
|
48
|
+
mail from: "noreply@example.com",
|
49
|
+
to: user.email,
|
44
|
-
|
50
|
+
subject: 'Account activation'
|
45
51
|
end
|
46
52
|
|
47
|
-
# Preview this email at
|
48
|
-
#
|
53
|
+
# Subject can be set in your I18n file at config/locales/en.yml
|
54
|
+
# with the following lookup:
|
55
|
+
#
|
56
|
+
# en.user_mailer.password_reset.subject
|
57
|
+
#
|
49
58
|
def password_reset
|
50
|
-
|
59
|
+
@greeting = "Hi"
|
60
|
+
|
61
|
+
mail to: "to@example.org"
|
51
62
|
end
|
52
63
|
end
|
64
|
+
|
53
65
|
```
|
54
|
-
> account_activation.html.erb
|
55
|
-
```ruby
|
56
|
-
<h1>Sample App</h1>
|
57
66
|
|
58
|
-
<p>Hi <%= @user.name %>,</p>
|
59
67
|
|
60
|
-
<p>
|
61
|
-
Welcome to the Sample App! Click on the link below to activate your account:
|
62
|
-
|
68
|
+
> mailer生成
|
63
|
-
|
69
|
+
```
|
64
|
-
|
70
|
+
rails generate mailer UserMailer account_activation password_reset
|
65
|
-
email: @user.email) %>
|
66
|
-
|
67
71
|
```
|