Now sends mail to user_target on message creation
This commit is contained in:
@@ -35,7 +35,9 @@ class MessagesController < ApplicationController
|
||||
return
|
||||
end
|
||||
@message = Message.new(message_params)
|
||||
@message.user_target = User.find(@message.user_target_id)
|
||||
if @message.save
|
||||
@message.send_new_message_mail
|
||||
flash[:notice] = "Message sent!"
|
||||
redirect_to messages_path
|
||||
return
|
||||
|
||||
@@ -24,4 +24,4 @@ module MailerHelper
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,4 +44,10 @@ class RedstonerMailer < ActionMailer::Base
|
||||
@user = user
|
||||
mail(to: @user.email, subject: "Email change on Redstoner.com")
|
||||
end
|
||||
|
||||
def new_message_mail(user, message)
|
||||
@user = user
|
||||
@message = message
|
||||
mail(to: @user.email, subject: "#{message.user_sender.name} sent you a new message.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class Message < ActiveRecord::Base
|
||||
|
||||
include MailerHelper
|
||||
|
||||
belongs_to :user_sender, class_name: "User", foreign_key: "user_sender_id"
|
||||
belongs_to :user_target, class_name: "User", foreign_key: "user_target_id"
|
||||
|
||||
@@ -17,4 +19,16 @@ class Message < ActiveRecord::Base
|
||||
# can be nil
|
||||
@target ||= user_target
|
||||
end
|
||||
|
||||
def send_new_message_mail
|
||||
begin
|
||||
mail = RedstonerMailer.new_message_mail(user_target, self)
|
||||
rescue => e
|
||||
Rails.logger.error "---"
|
||||
Rails.logger.error "WARNING: Failed to create new_message_mail (view) for message#: #{@message.id}, user: #{@user.name}, #{@user.email}"
|
||||
Rails.logger.error e.message
|
||||
Rails.logger.error "---"
|
||||
end
|
||||
background_mailer([mail])
|
||||
end
|
||||
end
|
||||
|
||||
28
app/views/redstoner_mailer/new_message_mail.html.erb
Normal file
28
app/views/redstoner_mailer/new_message_mail.html.erb
Normal file
@@ -0,0 +1,28 @@
|
||||
<div style="font-family: 'Oswald','Calibri','Arial','DejaVu Sans','Open Sans','Lucida Sans','Lucida Grande','Lucida Sans Unicode',sans-serif; background: #F2F2F2">
|
||||
<div style="color: #3f3f3f; width: 600px; max-width: 100%; padding: 2em 0; margin: auto;">
|
||||
Hi <%= @user.name %>!
|
||||
|
||||
<p><%= link_to @message.user_sender.name, user_url(@message.user_sender), style: "text-decoration: none; color: #4096EE;" %> has sent you a new message!</p>
|
||||
|
||||
<blockquote>
|
||||
<%= render_md(@message.text).html_safe %>
|
||||
</blockquote>
|
||||
|
||||
<p><%= link_to "Click here", messages_path %> to view your current messages.</p>
|
||||
|
||||
<p>If you have any questions or problems, just ask one of our <%= link_to "Staff", users_url(role: "staff"), style: "text-decoration: none; color: #4096EE;" %> in-game or on the forums!</p>
|
||||
<p>Your Redstoner team</p>
|
||||
|
||||
</div>
|
||||
<div style="background: #444; width: 100%; color: #fff; margin: auto; text-align: center; display: inline-block;">
|
||||
<div style="margin: 2em;">
|
||||
<p><i>Too much spam? Change <%= link_to "your notification settings", edit_notifications_user_url(@user), style: "text-decoration: none; color: #4096EE;" %>!</i></p>
|
||||
<p>You can contact us via:
|
||||
<%= link_to "Website", root_url, style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Twitter", "https://twitter.com/RedstonerServer", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Google+", "https://google.com/+Redstoner", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,4 +29,4 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user