0

I was creating a tableless model in Rails 4 for supporting sending emails easily.

So i have the following model:

class Message
  include ActiveModel::Model

  attr_accessor :subject, :content, :email
end

The following controller:

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

The form:

<%= 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 %>

But when i try to send an email here i what i got:

#<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

The error says its in here UserMailer.send(message)

Can someone help me?

4

1 回答 1

0

Kernel.send您调用的方法UserMailer只接受一个符号或一个字符串,而您试图向它传递一个Message. 您可能正在寻找其他方法UserMailer。通常,您将在子类上定义和调用自己的方法ActionMailer::Base。有关详细信息,请参阅指南

于 2013-07-18T21:27:07.143 回答