Fix subscribe system for rails5

This commit is contained in:
yafeilee 2016-04-27 12:22:37 +08:00
parent 91e9201bea
commit 8203757d1e
14 changed files with 8 additions and 12 deletions

View File

@ -48,7 +48,6 @@
}
.recent-title {
border-bottom: 1px solid #DCDCDC;
margin-bottom: 1rem;
}

View File

@ -3,7 +3,7 @@ class CommentMailer < ActionMailer::Base
default from: "no-reply@#{domain}"
def new(comment_id, to)
def born(comment_id, to)
@comment = Comment.find(comment_id)
mail to: to, subject: '博主, 你的博客有新的评论'
end

View File

@ -3,7 +3,7 @@ class PostMailer < ActionMailer::Base
default from: "no-reply@#{domain}"
def new(post_id, to)
def born(post_id, to)
@post = Post.find(post_id)
mail to: to, subject: '客官, 新博客来了'
end

View File

@ -7,10 +7,10 @@ class Comment < ApplicationRecord
validates :content, presence: true
def reply_emails
Comment.where(post_id: self.post_id).collect(&:email).uniq - [ self.email ] - Subscribe.unsubscribe_list
Comment.where(post_id: self.post_id).collect(&:email).uniq - [ self.email ] - Subscribe.unsubscribe_list - [ ENV['ADMIN_USER'] ]
end
after_create do
after_commit on: :create do
if ENV['MAIL_SERVER'].present? && ENV['ADMIN_USER'].present? && ENV['ADMIN_USER'] =~ /@/
Rails.logger.info 'comment created, comment worker start'
NewCommentWorker.perform_async(self.id.to_s, ENV['ADMIN_USER'])

View File

@ -8,7 +8,7 @@ class Post < ActiveRecord::Base
validates :title, :presence=>true, :uniqueness=> true
validates :content, :presence=>true, :length => { :minimum=> 30 }
after_create do
after_commit on: :create do
if ENV['MAIL_SERVER'].present?
NewPostWorker.perform_async(self.id.to_s)
end

View File

@ -1,2 +0,0 @@
h1 Unsubscribes#create
p Find me in app/views/unsubscribes/create.html.slim

View File

@ -7,7 +7,7 @@ class NewCommentWorker
def perform(comment_id, to)
logger.info "new comment mail: #{comment_id}"
CommentMailer.new(comment_id.to_s, to).deliver
CommentMailer.born(comment_id.to_s, to).deliver
end
end

View File

@ -8,7 +8,7 @@ class NewPostWorker
def perform(post_id)
Subscribe.subscribe_list.each do |email|
Rails.logger.info "new post #{post_id}, send to #{email}"
PostMailer.new(post_id.to_s, email).deliver
PostMailer.born(post_id.to_s, email).deliver
end
end
end

View File

@ -9,7 +9,6 @@ class NewReplyPostWorker
logger.info "new reply mail"
comment = Comment.find(comment_id.to_s)
comment.reply_emails.each do |email|
next if email == ENV['ADMIN_USER']
logger.info "new reply mail to #{email}"
CommentMailer.reply(comment_id.to_s, email).deliver
end

View File

@ -24,7 +24,7 @@ WBlog::Application.configure do
# number of complex assets.
config.assets.debug = true
config.middleware.insert_before 0, "Rack::Cors" do
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]