我正在嘗試使用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
謝謝!有效 –