mail_formを使用して連絡先フォームを1ページのWebページに配置しようとしています。しかし、私は指示書に従うのが難しいと思っています。具体的にはフォームのビューがあると仮定していますが、私のケースではすべてがコントローラーにあります。visitors_controller。 説明書によると、このように見ているコントローラがあるはずです:レール、1ページの連絡フォーム
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
ありがとうございます!出来た –