0

我按照这个网站的教程将mailboxer 实现到Ruby on Rails Web 应用程序中。

现在我收到这个错误:

ArgumentError in Messages#create
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

这是我的messages_controller.rb

    class MessagesController < ApplicationController

      def new
        @chosen_recipient = User.find_by(id: params[:to].to_i) if params[:to]
      end

      def create
        recipients = User.where(id: params['recipients'])
        conversation = current_user.send_message(recipients, params[:message] 
        [:body], params[:message][:subject]).conversation
        flash[:success] = "Message has been sent!"
        redirect_to conversation_path(conversation)
      end

    end

我不确定它有什么问题,因为我完全按照教程进行操作。

错误行具体是第 9 行“conversation = current_user.send_message......”

我相信我必须在某处定义@recipients,但本教程没有指定。

我已经尝试过@recipients 和@conversations,这只会导致另一个我不熟悉修复的错误(这只是为了实验)。

所有代码都在教程中,并在顶部链接。

可以在此链接上克隆存储库(使用 AWS Cloud9)并创建用户,然后尝试向另一个用户发送消息,当单击将消息发送给收件人时,您将收到错误消息。

我已经尝试执行之前列出的建议并尝试@ing 一些变量,但它没有奏效。

4

1 回答 1

0

您需要告诉 Rails 您的电子邮件服务器在每个应用程序的环境文件中的位置。就像是:

config.action_mailer.default_url_options = { :host => "www.yourhost.com" }

此外,在您在这里发布问题之前,您应该尝试在 Google 上搜索错误消息。这是第一个结果Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

于 2019-04-27T23:26:11.900 回答