サイト内メッセージング システムを作成するために、Mailboxer を使用してサイトをセットアップしました。ここで、Mailboxer の電子メール機能を実装して、自分のサイトでメッセージが送信されたときに、ユーザーに通知する電子メールも受信できるようにしたいと考えています。
ドキュメントを検索しましたが、電子メール側の設定に関するドキュメントはないようです。これまでのところ、gem のapp/mailer/
ディレクトリからメーラー クラスを取得しapp/mailer/
、メールボックス フォルダー内のディレクトリに配置しました。( app/mailer/mailboxer/
)。現在、これらのメーラーのメソッドをどのように利用すればよいかわかりません。
以下は、私がインサイト メッセージング用にセットアップしたコントローラーで、正常に動作しています。
メッセージ コントローラー:
class MessagesController < ApplicationController
# GET /message/new
def new
@request = Request.find(params[:request])
@message = current_user.messages.new
@user = @request.user
end
def reply
@conversation ||= current_user.mailbox.conversations.find(params[:id])
end
# POST /message/create
def create
@user = User.find(params[:user])
@body = params[:body]
@subject = params[:subject]
current_user.send_message(@user, params[:body], params[:subject])
flash[:notice] = "Message has been sent!"
redirect_to :conversations
end
end
会話コントローラー:
class ConversationsController < ApplicationController
before_filter :authenticate_user!
helper_method :mailbox, :conversation
def index
@conversations ||= current_user.mailbox.inbox.all
end
def reply
current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
redirect_to conversation_path(conversation)
end
def trashbin
@trash ||= current_user.mailbox.trash.all
end
def trash
conversation.move_to_trash(current_user)
redirect_to :conversations
end
def untrash
conversation.untrash(current_user)
redirect_to :back
end
def empty_trash
current_user.mailbox.trash.each do |conversation|
conversation.receipts_for(current_user).update_all(:deleted => true)
end
redirect_to :conversations
end
private
def mailbox
@mailbox ||= current_user.mailbox
end
def conversation
@conversation ||= mailbox.conversations.find(params[:id])
end
def conversation_params(*keys)
fetch_params(:conversation, *keys)
end
def message_params(*keys)
fetch_params(:message, *keys)
end
def fetch_params(key, *subkeys)
# debugger
params[key].instance_eval do
# debugger
case subkeys.size
when 0 then
self
when 1 then
self[subkeys.first]
else
subkeys.map { |k| self[k] }
end
end
end
end
次のように、message_controller のメソッドでnew_message_email
message_mailer 関数を使用してみました。create
def create
@user = User.find(params[:user])
@body = params[:body]
@subject = params[:subject]
current_user.send_message(@user, params[:body], params[:subject])
new_message_mailer(@subject, @user)
flash[:notice] = "Message has been sent!"
redirect_to :conversations
end
しかし、それは私にエラーを与えているundefined method 'new_message_email' for #<MessagesController:...>
ので、どうやら私は何をしているのかわかりません。これを設定するために必要なことを誰か教えてください。どんなアドバイスでも大歓迎です。