嗨,我试图在我的 ruby 项目中安装一个联系表单,用户可以在其中向指定的地址发送电子邮件。我无法在我的网站上显示联系表格,不断收到错误 *Expected H:/Sites/whatsonnew/app/controllers/contact_form_controller.rb to define 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'