sends emails [#23]

This commit is contained in:
rgarcia
2015-08-07 20:52:53 +02:00
parent 6803dc9d74
commit 3752054aab
9 changed files with 62 additions and 1 deletions

View File

@@ -7,6 +7,10 @@ class CommentsController < ApplicationController
@comment = Comment.build(@debate, current_user, params[:comment][:body])
@comment.save!
@comment.move_to_child_of(@parent) if reply?
Mailer.comment(@comment).deliver_now
Mailer.reply(@comment).deliver_now
respond_with @comment
end

View File

@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "participacion@madrid.es"
layout 'mailer'
end

16
app/mailers/mailer.rb Normal file
View File

@@ -0,0 +1,16 @@
class Mailer < ApplicationMailer
def comment(comment)
@comment = comment
@debate = comment.debate
mail(to: @debate.author.email, subject: t('mailer.comment.subject'))
end
def reply(reply)
@reply = reply
@debate = @reply.debate
parent = Comment.find(@reply.parent_id)
mail(to: parent.author.email, subject: t('mailer.reply.subject'))
end
end

View File

@@ -17,4 +17,13 @@ class Comment < ActiveRecord::Base
def self.find_parent(params)
params[:commentable_type].constantize.find(params[:commentable_id])
end
def debate
commentable if commentable.class == Debate
end
def author
user
end
end

View File

@@ -0,0 +1,5 @@
<html>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,7 @@
Hello,
<div><%= @comment.author.name %></div>
<div><%= @comment.body %></div>
<div><%= link_to @debate.title, debate_url(@debate) %></div>

View File

@@ -0,0 +1,7 @@
Hello,
<div><%= @reply.author.name %></div>
<div><%= @reply.body %></div>
<div><%= link_to @debate.title, debate_url(@debate) %></div>

View File

@@ -73,3 +73,8 @@ en:
shared:
tags_cloud:
tags: Tags
mailer:
comment:
subject: Someone has commented on your debate
reply:
subject: Someone has replied to your comment

View File

@@ -73,4 +73,8 @@ es:
shared:
tags_cloud:
tags: Etiquetas
mailer:
comment:
subject: Alguien ha comentado en tu debate
reply:
subject: Alguien ha respondido a tu comentario