简体   繁体   English

消息中的ArgumentError#在Ruby on Rails中为Mailboxer创建

[英]ArgumentError in Messages#create for Mailboxer in Ruby on Rails

I followed this site's tutorial on implementing mailboxer into a Ruby on Rails web application . 我按照本网站的教程将实施邮箱的方法应用到Ruby on Rails Web应用程序中

Right now I'm getting this error: 现在我收到这个错误:

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

Here is my messages_controller.rb 这是我的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

I'm not sure what is wrong with it as I followed the tutorial fully. 当我完全遵循教程时,我不确定它有什么问题。

The error line specifically is line 9 "conversation = current_user.send_message......" 错误行具体是第9行“conversation = current_user.send_message ......”

I believe I would have to define @recipients somewhere but the tutorial doesn't specify. 我相信我必须在某处定义@recipients,但教程没有指定。

I have tried @recipients and @conversations that only leads to another error that I'm not familiar with fixing (this was just for experimentation). 我试过@recipients和@conversations只会导致另一个我不熟悉修复的错误(这只是为了实验)。

All the code is in the tutorial as well linked at the top. 所有代码都在教程中,并在顶部链接。

The repo can be cloned at this link (using AWS Cloud9) and create users to then try to message another user and you will get the error message when clicking to send the message to the recipient. 可以在此链接上克隆repo(使用AWS Cloud9)并创建用户然后尝试向另一个用户发送消息,当您单击将消息发送给收件人时,您将收到错误消息。

I have tried to do the suggestions previously listed and experimented with @ing some of the variables but it did not work. 我试图做一些先前列出的建议并尝试使用@ing一些变量,但它没有用。

You need to tell Rails where your email server is in each of your application's environment files. 您需要告诉Rails您的电子邮件服务器位于每个应用程序的环境文件中。 Something like: 就像是:

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

Also, before you post a question here, you should try searching Google for the error message. 此外,在此处发布问题之前,您应该尝试在Google上搜索错误消息。 This was the first result for Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true 这是 Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true 的第一个结果 Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM