我无法弄清楚这个问题,即使它看起来并不复杂......
我想制作一个表格以在我的 Rails 应用程序中发送电子邮件,但这个表格不起作用。我收到以下错误:
TypeError in MessagesController#create
:
#<Message content: "test", email: "test@test.fr", name: "test"> is not a symbol
错误发生在:app/controllers/messages_controller.rb:10:in 'create'
1.这是我的messages_controller
:
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
Messenger.send(@message).deliver
redirect_to root_url, notice: "Message sent! Thank you for contacting us."
else
render "new"
end
end
end
形式
new.html.erb
:<%= form_for @message do |f| %> <%= f.text_field :name %> <%= f.text_field :email %> <%= f.text_area :content, :rows => 5 %> <%= f.submit "Send Message" %> <% end %>
Message
使用以下方法构建的模型ActiveAttr
:class Message include ActiveAttr::Model attribute :name attribute :email attribute :content end
我的
Messenger
邮件:class Messenger < ActionMailer::Base default :from => "test@test.com" def send(message) mail(:to => "test@test.com", :subject => "test") end end
谢谢您的帮助!