Using the Mail_form Gem in rails, I can verify that my mail configuration is correct; however I don't receive any errors in my logs.
contact.rb [app/models/contact.rb]
class Contact < MailForm::Base
include MailForm::Delivery
attribute :name, :validate => true
attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :message
attribute :nickname, :captcha => false
# Declare the e-mail headers. It accepts anything the mail method
# in ActionMailer accepts.
def headers
{
:subject => "IT Site Contact",
:to => "kompinski@gmail.com",
:from => %("#{name}" <#{email}>)
}
end
end
contacts_controller.rb
class ContactsController < ApplicationController
def new
@contact = Contact.new(params[:contact])
end
def create
@contact = Contact.new(params[:contact])
@contact.request = request
@contact.deliver
end
end
routes.rb
resources :contacts, only: [:new, :create]
get 'contact' => 'contacts#new'
post 'contact' => 'contacts#create'
new.html.erb [/views/contacts/new.html.erb]
<div class="container">
<div class="col-md-6"><h2>Contact us</h2>
<hr />
<form role="form">
<%= twitter_bootstrap_form_for @contact, url: new_contact_path, method: :post do |f| %>
<div class="medium">
</div>
<div class="medium">
<%= f.text_field :name, :required => true %>
</div>
<div class="medium">
<%= f.email_field :email, :required => false %>
</div>
<div class="medium">
<%= f.text_area :message, :as => :text, :required => true %>
</div>
<div class="btn">
<%= f.submit 'Submit' %>
<% end %>
</div>
</form>
</div>
</div>
** Edit ** Also I can send it directly from the form by using Contact.new(params[:contact]).deliver, but only when resubmit the address; however when I load the page containing the form it indicates 'undefined method `model_name' for TrueClass:Class'
This code worked for my controller where the issue seemed to be:
def new
@contact = Contact.new
if
Contact.new(params[:contact]).deliver
redirect_to '/contacts/thanks', :alert => ["Yeah!"]
end