@@ -15,10 +15,8 @@ class ContactMessagesController < ApplicationController |
||
| 15 | 15 |
@contact_message.user = current_user |
| 16 | 16 |
end |
| 17 | 17 |
@contact_message.unread = true |
| 18 |
- to_address = Info.first.contact_email |
|
| 19 | 18 |
respond_to do |format| |
| 20 | 19 |
if @contact_message.save |
| 21 |
- UserMailer.contact_message(@contact_message, to_address).deliver |
|
| 22 | 20 |
format.html { redirect_to contact_messages_path, notice: (t 'contact.delivered') }
|
| 23 | 21 |
format.json { render action: 'show', status: :created, location: @contact_message }
|
| 24 | 22 |
else |
@@ -5,7 +5,6 @@ class SubscriptionController < ApplicationController |
||
| 5 | 5 |
respond_to do |format| |
| 6 | 6 |
if Subscription.find_by_email(@subscription.email) == nil |
| 7 | 7 |
if @subscription.save |
| 8 |
- UserMailer.newsletter_subscription(@subscription).deliver |
|
| 9 | 8 |
format.html { redirect_to root_path, notice: 'Thanks for subscribing to our newsletter' }
|
| 10 | 9 |
format.json { render action: 'show', status: :created, location: @subscription }
|
| 11 | 10 |
else |
@@ -1,6 +1,10 @@ |
||
| 1 | 1 |
class ContactMessage < ActiveRecord::Base |
| 2 | 2 |
belongs_to :user |
| 3 | 3 |
|
| 4 |
+ after_create do |
|
| 5 |
+ send_contact_message |
|
| 6 |
+ end |
|
| 7 |
+ |
|
| 4 | 8 |
def name |
| 5 | 9 |
if user != nil |
| 6 | 10 |
name = self.user.first_name.to_s + ' ' + self.user.last_name.to_s |
@@ -10,4 +14,8 @@ class ContactMessage < ActiveRecord::Base |
||
| 10 | 14 |
return name |
| 11 | 15 |
end |
| 12 | 16 |
|
| 17 |
+ def send_contact_message |
|
| 18 |
+ Resque.enqueue(SendContactMessage, self.id) |
|
| 19 |
+ end |
|
| 20 |
+ |
|
| 13 | 21 |
end |
@@ -2,6 +2,7 @@ class Subscription < ActiveRecord::Base |
||
| 2 | 2 |
|
| 3 | 3 |
after_create do |
| 4 | 4 |
subscribe_to_mailchimp |
| 5 |
+ send_newsletter_subscription_email |
|
| 5 | 6 |
end |
| 6 | 7 |
|
| 7 | 8 |
def full_name |
@@ -21,4 +22,10 @@ class Subscription < ActiveRecord::Base |
||
| 21 | 22 |
Resque.enqueue(SubscribeToMailchimp, self.id) |
| 22 | 23 |
end |
| 23 | 24 |
|
| 25 |
+ def send_newsletter_subscription_email |
|
| 26 |
+ if User.find_by_email(self.email) == nil |
|
| 27 |
+ Resque.enqueue(SendNewsletterSubscription, self.id) |
|
| 28 |
+ end |
|
| 29 |
+ end |
|
| 30 |
+ |
|
| 24 | 31 |
end |
@@ -0,0 +1,15 @@ |
||
| 1 |
+class SendContactMessage |
|
| 2 |
+ @queue = :send_contact_message_queue |
|
| 3 |
+ |
|
| 4 |
+ def self.perform(id) |
|
| 5 |
+ |
|
| 6 |
+ # Get contact message |
|
| 7 |
+ msg = ContactMessage.find_by_id(id) |
|
| 8 |
+ # Get webmaster email addresss |
|
| 9 |
+ to_address = Info.first.contact_email |
|
| 10 |
+ # Send Contact Message Email |
|
| 11 |
+ UserMailer.contact_message(msg, to_address).deliver |
|
| 12 |
+ |
|
| 13 |
+ end |
|
| 14 |
+ |
|
| 15 |
+end |
@@ -0,0 +1,13 @@ |
||
| 1 |
+class SendNewsletterSubscription |
|
| 2 |
+ @queue = :send_newsletter_subscription_queue |
|
| 3 |
+ |
|
| 4 |
+ def self.perform(id) |
|
| 5 |
+ |
|
| 6 |
+ # Get subscription |
|
| 7 |
+ subscription = Subscription.find_by_id(id) |
|
| 8 |
+ # Send newsletter subscription email |
|
| 9 |
+ UserMailer.newsletter_subscription(subscription).deliver |
|
| 10 |
+ |
|
| 11 |
+ end |
|
| 12 |
+ |
|
| 13 |
+end |