【发布时间】:2014-03-29 02:18:59
【问题描述】:
我对此比较陌生。我正在尝试将 URL 路由到表单,然后将该表单发送到联系电子邮件。这是我得到的错误。 当我搜索路由时,我发现实际上 send_mail 没有 POST 之类的东西。但我不确定为什么一开始就没有。而且我不确定如何放入...
Routing Error
No route matches [POST] "/send_mail"
Rails.root: /home/nadia/blog
这是我的联系人控制器:
1 class ContactController < ApplicationController
2 def new
3 end
4
5 def send_mail
6 name = params[:name]
7 email = params[:email]
8 message = params [:message]
9 ContactUs.contact_email(name, email, message).deliver
10 redirect_to contact_path, notice: 'Message Sent'
11 end
这是我的应用程序/mailer/contact_us.rb
1 class ContactUs < ActionMailer::Base
2 default to: "my@email.com"
3 default from: "my@email.com"
4
5 def contact_email (name, email, message)
6 @name = name
7 @email = email
8 @message = message
9
10 mail(from: name, subject: 'Contact')
11 end
12 end
13
如果我可以向您展示任何其他文件,请告诉我 提前谢谢!
【问题讨论】:
标签: rest ruby-on-rails-4 routing actionmailer