我正在尝试使用mail_form将联系表单放入单页网页中。但是,我发现很难按照说明进行操作,因为他们认为我特意为表单提供了一个视图,但在我的情况下,所有内容都在控制器visitors_controller中。 根据指示,应该找一个像这样的控制器:Rails,单页中的联系表单
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(params[:contact])
@contact.request = request
if @contact.deliver
flash.now[:notice] = 'Thank you for your message. We will contact you soon!'
else
flash.now[:error] = 'Cannot send message.'
render :new
end
end
end
而且认为应该是这样的:
<%= simple_form_for @contact, html: {class: 'form-horizontal' } do |f| %>
<%= f.input :name, :required => true %>
<%= f.input :email, :required => true %>
<%= f.input :message, :as => :text, :required => true %>
<div class= "hidden">
<%= f.input :nickname, :hint => 'Leave this field blank!' %>
</div>
<%= f.button :submit, 'Send message', :class=> "btn btn-primary" %>
<% end %>
如何实现同我visitors_controller并查看? 控制器目前看起来是这样的,如果它是重要的
class VisitorsController < ApplicationController
def index
end
end
谢谢!有效 –