質問編集履歴
1
コードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,4 @@
|
|
1
|
-
rails チュートリアル11章のメイラーの部分をやっています。applicatoin_mailer.rbのdefault from: の部分を変えてもプレビューで反映されません
|
1
|
+
rails チュートリアル11章のメイラーの部分をやっています。applicatoin_mailer.rbのdefault from: の部分を変えてもプレビューで反映されませんでした。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
> mailer生成
|
6
|
-
|
7
|
-
```
|
8
|
-
|
9
|
-
rails generate mailer UserMailer account_activation password_reset
|
10
|
-
|
11
|
-
```
|
12
|
-
|
13
|
-
|
14
2
|
|
15
3
|
![イメージ説明](f9c3ade4042e4f61b5cfe5dc621a4fe0.png)
|
16
4
|
|
@@ -64,70 +52,90 @@
|
|
64
52
|
|
65
53
|
```
|
66
54
|
|
55
|
+
その後、user_mailer.rbで個別にfrom:で設定したところ、問題なく動作しました。
|
56
|
+
|
57
|
+
なぜdefault from: では反映されなかったのでしょうか?
|
58
|
+
|
59
|
+
![![イメージ説明](c055b795808a9a31a7afbb8bcf1ac22d.png)
|
60
|
+
|
67
|
-
>
|
61
|
+
> application_mailer.rb
|
68
62
|
|
69
63
|
```ruby
|
70
64
|
|
71
|
-
|
65
|
+
class ApplicationMailer < ActionMailer::Base
|
72
66
|
|
67
|
+
layout 'mailer'
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
> user_mailer.rb
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
|
73
|
-
class UserMailer
|
77
|
+
class UserMailer < ApplicationMailer
|
74
78
|
|
75
79
|
|
76
80
|
|
77
|
-
#
|
81
|
+
# Subject can be set in your I18n file at config/locales/en.yml
|
78
82
|
|
79
|
-
# ht
|
83
|
+
# with the following lookup:
|
80
84
|
|
81
|
-
|
85
|
+
#
|
82
86
|
|
83
|
-
user
|
87
|
+
# en.user_mailer.account_activation.subject
|
84
88
|
|
85
|
-
|
89
|
+
#
|
86
90
|
|
87
|
-
|
91
|
+
def account_activation(user)
|
92
|
+
|
93
|
+
@user = user
|
94
|
+
|
95
|
+
mail from: "noreply@example.com",
|
96
|
+
|
97
|
+
to: user.email,
|
98
|
+
|
99
|
+
subject: 'Account activation'
|
88
100
|
|
89
101
|
end
|
90
102
|
|
91
103
|
|
92
104
|
|
93
|
-
#
|
105
|
+
# Subject can be set in your I18n file at config/locales/en.yml
|
94
106
|
|
107
|
+
# with the following lookup:
|
108
|
+
|
109
|
+
#
|
110
|
+
|
95
|
-
#
|
111
|
+
# en.user_mailer.password_reset.subject
|
112
|
+
|
113
|
+
#
|
96
114
|
|
97
115
|
def password_reset
|
98
116
|
|
99
|
-
|
117
|
+
@greeting = "Hi"
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
mail to: "to@example.org"
|
100
122
|
|
101
123
|
end
|
102
124
|
|
103
125
|
end
|
104
126
|
|
127
|
+
|
128
|
+
|
105
129
|
```
|
106
|
-
|
107
|
-
> account_activation.html.erb
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
|
111
|
-
<h1>Sample App</h1>
|
112
130
|
|
113
131
|
|
114
132
|
|
115
|
-
<p>Hi <%= @user.name %>,</p>
|
116
133
|
|
117
134
|
|
118
|
-
|
119
|
-
<p>
|
120
|
-
|
121
|
-
Welcome to the Sample App! Click on the link below to activate your account:
|
122
|
-
|
123
|
-
|
135
|
+
> mailer生成
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
<%= link_to "Activate", edit_account_activation_url(@user.activation_token,
|
128
|
-
|
129
|
-
email: @user.email) %>
|
130
|
-
|
131
|
-
|
132
136
|
|
133
137
|
```
|
138
|
+
|
139
|
+
rails generate mailer UserMailer account_activation password_reset
|
140
|
+
|
141
|
+
```
|