1

我已经使用 Mailboxer 设置了我的站点,以创建一个站点内消息传递系统。现在我想实现 Mailboxer 的电子邮件功能,以便当在我的站点中发送消息时,用户也会收到一封通知他们的电子邮件。

我已经搜索了文档,但似乎没有任何用于设置电子邮件方面的内容。到目前为止,我已经从 gem 的app/mailer/目录中获取了 mailer classes,并将它们放在我的app/mailer/目录中,在他们的 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

我尝试new_message_email在我的 messages_controller 方法中使用 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:...>,所以显然我不知道我在做什么。谁能给我一个我需要做些什么来设置它?任何意见是极大的赞赏。

4

0 回答 0