我使用Mailboxer设置我的网站以创建一个站内消息系统。现在我想实现Mailboxer的电子邮件功能,这样当我的网站发送邮件时,用户也会收到一封电子邮件通知他们。
我搜索了文档,但似乎没有任何设置电子邮件方面的东西。到目前为止,我已经从gem的app/mailer/
目录中获取了mailer classess,并将它们放在我们的app/mailer/
目录中,在其邮箱文件夹中。 (app/mailer/mailboxer/
)。现在我不确定如何使用这些邮件中的方法。
以下是我为insite消息设置的控制器,它们正常工作:
消息控制器:
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
我尝试在我的messages_controller的new_message_email
方法中使用create
message_mailer函数,如下所示:
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:...>
,显然我不知道我在做什么。有谁能请给我一个我需要做的设置呢?非常感谢任何建议。