diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 409bb7c9b..c5c0fe0c7 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 000000000..e5d793e1e --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "participacion@madrid.es" + layout 'mailer' +end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb new file mode 100644 index 000000000..fa53c7c1a --- /dev/null +++ b/app/mailers/mailer.rb @@ -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 diff --git a/app/models/comment.rb b/app/models/comment.rb index e99ef15e3..c2cf75292 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 000000000..991cf0ffa --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,5 @@ + + + <%= yield %> + + diff --git a/app/views/mailer/comment.html.erb b/app/views/mailer/comment.html.erb new file mode 100644 index 000000000..f469d50b8 --- /dev/null +++ b/app/views/mailer/comment.html.erb @@ -0,0 +1,7 @@ +Hello, + +
<%= @comment.author.name %>
+ +
<%= @comment.body %>
+ +
<%= link_to @debate.title, debate_url(@debate) %>
\ No newline at end of file diff --git a/app/views/mailer/reply.html.erb b/app/views/mailer/reply.html.erb new file mode 100644 index 000000000..7714d7c28 --- /dev/null +++ b/app/views/mailer/reply.html.erb @@ -0,0 +1,7 @@ +Hello, + +
<%= @reply.author.name %>
+ +
<%= @reply.body %>
+ +
<%= link_to @debate.title, debate_url(@debate) %>
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 7fdf7a214..f32e3010e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/es.yml b/config/locales/es.yml index 9bbdde6b6..14e1c3b59 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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