我想在我的ruby项目中安装联系表单,用户可以将电子邮件发送到指定的地址。我在网站上显示联系表单时遇到问题,不断收到错误*预期H:/Sites/whatsonnew/app/controllers/contact_form_controller.rb来定义ContactFormController *。有什么想法吗?
联系表单控制器中的代码
class ContactFormsController < ApplicationController
def new
@contact_form = ContactForm.new
end
def create
begin
@contact_form = ContactForm.new(params[:contact_form])
@contact_form.request = request
if @contact_form.deliver
flash.now[:notice] = 'Thank you for your message!'
else
render :new
end
rescue ScriptError
flash[:error] = 'Sorry, this message appears to be spam and was not delivered.'
end
end
end
通过显示此链接来调用控制器
<li><%= link_to "Contact Form", controller: 'contact_form', action: 'new' %></li>
的routes.rb 我试过了
match 'contact_form/create' => 'contact#create'
match 'contact_form/new' => 'contact#new'
match 'contact_form' => 'contact#new'