inquiries 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +16 -0
- data/Rakefile +1 -0
- data/app/controllers/inquiries/inquiries_controller.rb +36 -0
- data/app/mailers/inquiries/inquiry_mailer.rb +21 -0
- data/app/models/inquiries/inquiry.rb +45 -0
- data/app/views/inquiries/inquiries/_error_messages.html.erb +10 -0
- data/app/views/inquiries/inquiries/new.html.erb +20 -0
- data/app/views/inquiries/inquiries/thank_you.html.erb +3 -0
- data/config/routes.rb +12 -0
- data/inquiries.gemspec +22 -0
- data/lib/generators/inquiries_generator.rb +14 -0
- data/lib/generators/templates/create_inquiries.rb +17 -0
- data/lib/generators/templates/inquiry.yml +4 -0
- data/lib/inquiries/rails/engine.rb +6 -0
- data/lib/inquiries/rails/version.rb +5 -0
- data/lib/inquiries/rails.rb +2 -0
- data/lib/inquiries.rb +1 -0
- metadata +98 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 John Colvin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Inquiries
|
2
|
+
|
3
|
+
This gem logs inquiries (via contact form) and sends email notifications for those inquiries.
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
|
7
|
+
In your Gemfile, add this line:
|
8
|
+
|
9
|
+
gem "inquiries"
|
10
|
+
|
11
|
+
Then, run `bundle install`.
|
12
|
+
|
13
|
+
Run the generator and migrate:
|
14
|
+
|
15
|
+
rails g inquiries
|
16
|
+
rake db:migrate
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Inquiries
|
2
|
+
class InquiriesController < ::ApplicationController
|
3
|
+
|
4
|
+
def thank_you
|
5
|
+
end
|
6
|
+
|
7
|
+
def new
|
8
|
+
@inquiry = Inquiries::Inquiry.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@inquiry = Inquiries::Inquiry.new(params[:inquiries_inquiry])
|
13
|
+
|
14
|
+
if @inquiry.save
|
15
|
+
if @inquiry.ham?
|
16
|
+
begin
|
17
|
+
Inquiries::InquiryMailer.notification(@inquiry, request).deliver
|
18
|
+
rescue
|
19
|
+
logger.warn "There was an error delivering an inquiry notification.\n#{$!}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
Inquiries::InquiryMailer.confirmation(@inquiry, request).deliver
|
24
|
+
rescue
|
25
|
+
logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
|
26
|
+
end if Inquiries::Inquiry.send_confirmation?
|
27
|
+
end
|
28
|
+
|
29
|
+
redirect_to thank_you_inquiries_inquiries_path
|
30
|
+
else
|
31
|
+
render :action => 'new'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Inquiries
|
2
|
+
class InquiryMailer < ActionMailer::Base
|
3
|
+
|
4
|
+
def confirmation(inquiry, request)
|
5
|
+
@inquiry = inquiry
|
6
|
+
mail :subject => Inquiries::Inquiry.confirmation_subject,
|
7
|
+
:to => inquiry.email,
|
8
|
+
:from => "\"#{Rails.application.class.parent_name}\" <no-reply@#{request.domain}>",
|
9
|
+
:reply_to => Inquiries::Inquiry.notification_recipients.split(',').first
|
10
|
+
end
|
11
|
+
|
12
|
+
def notification(inquiry, request)
|
13
|
+
@inquiry = inquiry
|
14
|
+
mail :subject => Inquiries::Inquiry.notification_subject,
|
15
|
+
:to => Refinery::Inquiries::Setting.notification_recipients,
|
16
|
+
:from => "\"#{Rails.application.class.parent_name}\" <no-reply@#{request.domain}>",
|
17
|
+
:reply_to => inquiry.email
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'filters_spam'
|
2
|
+
|
3
|
+
module Inquiries
|
4
|
+
class Inquiry < ActiveRecord::Base
|
5
|
+
|
6
|
+
filters_spam :message_field => :message,
|
7
|
+
:email_field => :email,
|
8
|
+
:author_field => :name
|
9
|
+
|
10
|
+
validates :name, :presence => true
|
11
|
+
validates :email, :format=> { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
|
12
|
+
validates :message, :presence => true
|
13
|
+
|
14
|
+
default_scope :order => 'created_at DESC'
|
15
|
+
|
16
|
+
attr_accessible :name, :message, :email
|
17
|
+
|
18
|
+
def self.latest(number = 7, include_spam = false)
|
19
|
+
include_spam ? limit(number) : ham.limit(number)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.send_confirmation?
|
23
|
+
settings['send-confirmation'] ? true : false
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.notification_recipients
|
27
|
+
settings['notification-recipients']
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.notification_subject
|
31
|
+
settings['notification-subject']
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.confirmation_subject
|
35
|
+
settings['confirmation-subject']
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def self.settings
|
41
|
+
@settings ||= YAML.load_file('config/inquiry.yml')
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% if object.errors.any? %>
|
2
|
+
<div class="errorExplanation" id="errorExplanation">
|
3
|
+
<p>There were problems with the following fields:</p>
|
4
|
+
<ul>
|
5
|
+
<% object.errors.full_messages.each do |value| %>
|
6
|
+
<li><%= value %></li>
|
7
|
+
<% end %>
|
8
|
+
</ul>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<div class='inquiries'>
|
2
|
+
<%= form_for @inquiry do |f| %>
|
3
|
+
<%= render "error_messages", :object => @inquiry %>
|
4
|
+
<div class="field">
|
5
|
+
<%= f.label :name %>
|
6
|
+
<%= f.text_field :name, :class => 'text', :required => 'required', :placeholder => 'Name' %>
|
7
|
+
</div>
|
8
|
+
<div class="field">
|
9
|
+
<%= f.label :email %>
|
10
|
+
<%= f.email_field :email, :class => 'text email', :required => 'required', :placeholder => 'Email' %>
|
11
|
+
</div>
|
12
|
+
<div class='field message_field'>
|
13
|
+
<%= f.label :message %>
|
14
|
+
<%= f.text_area :message, :rows => 8, :required => 'required', :placeholder => 'Message' %>
|
15
|
+
</div>
|
16
|
+
<div class="actions">
|
17
|
+
<%= f.submit 'Send Message' %>
|
18
|
+
</div>
|
19
|
+
<% end %>
|
20
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
namespace :inquiries, :path => '' do
|
3
|
+
get '/contact', :to => 'inquiries#new', :as => 'new_inquiry'
|
4
|
+
|
5
|
+
resources :contact,
|
6
|
+
:only => :create,
|
7
|
+
:as => :inquiries,
|
8
|
+
:controller => 'inquiries' do
|
9
|
+
get :thank_you, :on => :collection
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/inquiries.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'inquiries/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "inquiries"
|
8
|
+
gem.version = Inquiries::Rails::VERSION
|
9
|
+
gem.authors = ["John Colvin"]
|
10
|
+
gem.email = ["colvin.john@gmail.com"]
|
11
|
+
gem.description = "Extracted from the refinerycms-inquiries gem. Records inquiries in the DB and sends notifications via email"
|
12
|
+
gem.summary = "Records inquiries and sends email notifications"
|
13
|
+
gem.homepage = "http://github.com/JohnColvin/inquiries"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'filters_spam', '~> 0.2'
|
21
|
+
gem.add_dependency 'actionmailer'
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
class InquiriesGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
extend ActiveRecord::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
def copy_files(*args)
|
11
|
+
migration_template 'create_inquiries.rb', 'db/migrate/create_inquiries.rb'
|
12
|
+
copy_file 'inquiry.yml', 'config/inquiry.yml'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateInquiries < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
unless Inquiries::Inquiry.table_exists?
|
4
|
+
create_table :inquiries, :force => true do |t|
|
5
|
+
t.string :name
|
6
|
+
t.string :email
|
7
|
+
t.text :message
|
8
|
+
t.boolean :spam, :default => false
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
drop_table :inquiries
|
16
|
+
end
|
17
|
+
end
|
data/lib/inquiries.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "inquiries/rails"
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inquiries
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Colvin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: filters_spam
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: actionmailer
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Extracted from the refinerycms-inquiries gem. Records inquiries in the
|
47
|
+
DB and sends notifications via email
|
48
|
+
email:
|
49
|
+
- colvin.john@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- app/controllers/inquiries/inquiries_controller.rb
|
60
|
+
- app/mailers/inquiries/inquiry_mailer.rb
|
61
|
+
- app/models/inquiries/inquiry.rb
|
62
|
+
- app/views/inquiries/inquiries/_error_messages.html.erb
|
63
|
+
- app/views/inquiries/inquiries/new.html.erb
|
64
|
+
- app/views/inquiries/inquiries/thank_you.html.erb
|
65
|
+
- config/routes.rb
|
66
|
+
- inquiries.gemspec
|
67
|
+
- lib/generators/inquiries_generator.rb
|
68
|
+
- lib/generators/templates/create_inquiries.rb
|
69
|
+
- lib/generators/templates/inquiry.yml
|
70
|
+
- lib/inquiries.rb
|
71
|
+
- lib/inquiries/rails.rb
|
72
|
+
- lib/inquiries/rails/engine.rb
|
73
|
+
- lib/inquiries/rails/version.rb
|
74
|
+
homepage: http://github.com/JohnColvin/inquiries
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.24
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Records inquiries and sends email notifications
|
98
|
+
test_files: []
|