sends emails [#23]
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
4
app/mailers/application_mailer.rb
Normal file
4
app/mailers/application_mailer.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: "participacion@madrid.es"
|
||||
layout 'mailer'
|
||||
end
|
||||
16
app/mailers/mailer.rb
Normal file
16
app/mailers/mailer.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
5
app/views/layouts/mailer.html.erb
Normal file
5
app/views/layouts/mailer.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
||||
7
app/views/mailer/comment.html.erb
Normal file
7
app/views/mailer/comment.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
Hello,
|
||||
|
||||
<div><%= @comment.author.name %></div>
|
||||
|
||||
<div><%= @comment.body %></div>
|
||||
|
||||
<div><%= link_to @debate.title, debate_url(@debate) %></div>
|
||||
7
app/views/mailer/reply.html.erb
Normal file
7
app/views/mailer/reply.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
Hello,
|
||||
|
||||
<div><%= @reply.author.name %></div>
|
||||
|
||||
<div><%= @reply.body %></div>
|
||||
|
||||
<div><%= link_to @debate.title, debate_url(@debate) %></div>
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user