ActiveMailer
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
&tag(ActiveMailer);
*目次 [#oa98f0b6]
#contents
*関連ページ [#of9fdef1]
*参考情報 [#t743b261]
-[[Action Mailer の基礎 | Rails ガイド:https://railsguide...
*基本 [#yd6dc1fe]
**メイラークラスの作成 [#g5aa045e]
-ActiveMailer::Baseを継承したメイラークラスがメール送信機...
-「bin/rails generate mailer UserMailer」で以下のクラスが...
#pre{{
# app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
end
}}
-ジェネレータを使用せずに直接ActionMailer::Baseを継承して...
#pre{{
class MyMailer < ActionMailer::Base
end
}}
**メールの作成 [#b1ba966c]
-メーラークラスのインスタンスメソッドがメール送信、それに...
#pre{{
class UserMailer < ApplicationMailer
default from: 'notifications@example.com'
def welcome_email(user)
@user = user
@url = 'http://example.com/login'
mail(to: @user.email, subject: 'Welcome to My Awesome...
end
end
}}
-ビュー
#pre{{
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='...
</head>
<body>
<h1><%= @user.name %>様、example.comへようこそ。</h1>
<p>
example.comへのサインアップが成功しました。
your username is: <%= @user.login %>.<br>
</p>
<p>
このサイトにログインするには、<%= @url %>をクリック...
</p>
<p>ご入会ありがとうございます。どうぞお楽しみください...
</body>
</html>
}}
-呼び出しは普通にコントローラーから
#pre{{
class UsersController < ApplicationController
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
# 保存後にUserMailerを使用してwelcomeメールを送信
UserMailer.welcome_email(@user).deliver_later
format.html { redirect_to(@user, notice: 'ユーザ...
format.json { render json: @user, status: :create...
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: ...
end
end
end
end
}}
-welcome_emailメソッドはmailメソッドを呼び出し、そこでMai...
終了行:
&tag(ActiveMailer);
*目次 [#oa98f0b6]
#contents
*関連ページ [#of9fdef1]
*参考情報 [#t743b261]
-[[Action Mailer の基礎 | Rails ガイド:https://railsguide...
*基本 [#yd6dc1fe]
**メイラークラスの作成 [#g5aa045e]
-ActiveMailer::Baseを継承したメイラークラスがメール送信機...
-「bin/rails generate mailer UserMailer」で以下のクラスが...
#pre{{
# app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
end
}}
-ジェネレータを使用せずに直接ActionMailer::Baseを継承して...
#pre{{
class MyMailer < ActionMailer::Base
end
}}
**メールの作成 [#b1ba966c]
-メーラークラスのインスタンスメソッドがメール送信、それに...
#pre{{
class UserMailer < ApplicationMailer
default from: 'notifications@example.com'
def welcome_email(user)
@user = user
@url = 'http://example.com/login'
mail(to: @user.email, subject: 'Welcome to My Awesome...
end
end
}}
-ビュー
#pre{{
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='...
</head>
<body>
<h1><%= @user.name %>様、example.comへようこそ。</h1>
<p>
example.comへのサインアップが成功しました。
your username is: <%= @user.login %>.<br>
</p>
<p>
このサイトにログインするには、<%= @url %>をクリック...
</p>
<p>ご入会ありがとうございます。どうぞお楽しみください...
</body>
</html>
}}
-呼び出しは普通にコントローラーから
#pre{{
class UsersController < ApplicationController
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
# 保存後にUserMailerを使用してwelcomeメールを送信
UserMailer.welcome_email(@user).deliver_later
format.html { redirect_to(@user, notice: 'ユーザ...
format.json { render json: @user, status: :create...
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: ...
end
end
end
end
}}
-welcome_emailメソッドはmailメソッドを呼び出し、そこでMai...
ページ名: