Created
July 24, 2013 06:26
-
-
Save deepakdargade/6068436 to your computer and use it in GitHub Desktop.
mail_form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContactForm < MailForm::Base | |
attribute :name, :validate => true | |
attribute :nickname, :captcha => true | |
attribute :email, :validate => /[^@]+@[^\.]+\.[\w\.\-]+/ | |
attribute :message, :validate => true | |
def headers | |
origin = "#{name} <#{email}>" | |
return :subject => ::I18n.t(:subject, :scope => [:actionmailer, :contact_form]), | |
:from => origin, | |
:reply_to => origin, | |
:to => Settings.mailer.contact_email | |
end | |
def persisted? | |
false | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContactsController < ApplicationController | |
def new | |
@contact = ContactForm.new(params[:contact_form]) | |
end | |
def create | |
@contact = ContactForm.new(params[:contact_form]) | |
if @contact.valid? | |
@contact.deliver | |
redirect_to :root, :notice => tf('contact.thanks') | |
else | |
render :action => "new" | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'mail_form', '>= 1.2.1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= semantic_form_for @contact, :url => contact_us_path do |f| | |
= f.inputs :name => "Your Contact Details" do | |
= f.input :name | |
= f.input :nickname | |
= f.input :email | |
= f.inputs :name => "Your Message" do | |
= f.input :message, :input_html => {:rows => 8}, :as => :text | |
= f.buttons do | |
= f.commit_button "Contact Us" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment