Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 传递对象时发生Rails类型错误_Ruby On Rails_Model_Typeerror_Symbols - Fatal编程技术网

Ruby on rails 传递对象时发生Rails类型错误

Ruby on rails 传递对象时发生Rails类型错误,ruby-on-rails,model,typeerror,symbols,Ruby On Rails,Model,Typeerror,Symbols,我在Rails 4中创建了一个无表模型,用于支持轻松发送电子邮件 因此,我有以下模型: class Message include ActiveModel::Model attr_accessor :subject, :content, :email end 以下控制器: class MessagesController < ApplicationController def new @message = Message.new end def create

我在Rails 4中创建了一个无表模型,用于支持轻松发送电子邮件

因此,我有以下模型:

class Message
  include ActiveModel::Model

  attr_accessor :subject, :content, :email
end
以下控制器:

class MessagesController < ApplicationController
  def new
    @message = Message.new
  end

 def create
   message = Message.new(params[:message])
   if message.valid?
     UserMailer.send(message)
     redirect_to :back, :notice => "Email was successfully sent."
   else
     flash[:alert] = "You must fill all fields."
     render 'new'
   end
 end
end
class messages控制器“电子邮件已成功发送。”
其他的
flash[:alert]=“您必须填写所有字段。”
呈现“新”
结束
结束
结束
表格:

<%= form_for @message do |f| %>
  <%= f.label :email %>
  <%= f.text_field :email %>

  <%= f.label :subject %>
  <%= f.text_field :subject %>

  <%= f.label :content %>
  <%= f.text_area :content, rows: 5, class: 'span7' %>
  <%= f.submit "Send Email", class: 'btn btn-primary' %>

<% end %>

但当我尝试在这里发送电子邮件时,我得到了:

#<Message:0x007fcc98e8c760 @errors=#    <ActiveModel::Errors:0x007fcc98e96788 @base=#<Message:0x007fcc98e8c760 ...>, @messages={}>,     @email="sdsadas@adasdas.com", @subject="adasdas", @content="asdsad", @validation_context=nil> is not a symbol
#不是一个符号
错误显示它在这里UserMailer.send(message)


有人能帮我吗?

您正在调用的
UserMailer
方法只接受符号或字符串,而您正在尝试向其传递
消息的实例。您可能正在寻找
UserMailer
的其他方法。通常,您将在
ActionMailer::Base
子类上定义并调用自己的方法。有关详细信息,请参阅。

谢谢,我找到了答案,是的,这是因为我将方法命名为send,我更改了名称,结果很好=)