Witam
Czy moglibyście pomoc mi zrobić formularz kontaktowy bez przeładowywania strony?
index.html.erb
<%= simple_form_for @contact, :html => {:class => 'form-horizontal', :remote => true } do |f| %>
<div class="form-group">
<!--<label for="exampleInputName2">Imię</label>
<input type="text" class="form-control" id="exampleInputName2" placeholder="Jan Kowalski">-->
<%= f.input :name, :required => true, placeholder: 'Jan Kowalski',label: "Imię",input_html: { class: 'form-control' }%>
</div>
<div class="form-group">
<!--<label for="exampleInputEmail2">Email</label>
<input type="email" class="form-control" id="exampleInputEmail2" placeholder="jan.kowalski@przyklad.pl">-->
<%= f.input :email, :required => true, placeholder: 'jan.kowalski@przyklad.pl',label: "Email",input_html: { class: 'form-control' }%>
</div>
<div class="form-group ">
<!--<label for="exampleInputText">Twoja wiadomość</label>
<textarea class="form-control" placeholder="Opis"></textarea>-->
<%= f.input :message, :as => :text, :required => true, placeholder: 'Opis',label: "Twoja wiadomość",input_html: { class: 'form-control' }%>
</div>
<!--<button type="submit" class="btn btn-default">Wyślij wiadomość</button>-->
<%= f.button :submit, 'Wyślij wiadomość', :class=> "btn btn-default" %>
<% end %>
publiccontroller
layout 'public'
def index
@contact = Contact.new
end
contact model
class Contact < MailForm::Base
attribute :name, :validate => true, :class => "form-control"
attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :message
attribute :nickname, :captcha => true
# Declare the e-mail headers. It accepts anything the mail method
# in ActionMailer accepts.
def headers
{
:subject => "My Contact Form",
:to => "kafar610@gmail.com",
:from => %("#{name}" <#{email}>)
}
end
end