Fix subscribe system for rails5
This commit is contained in:
parent
91e9201bea
commit
8203757d1e
|
@ -48,7 +48,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.recent-title {
|
.recent-title {
|
||||||
border-bottom: 1px solid #DCDCDC;
|
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ class CommentMailer < ActionMailer::Base
|
||||||
|
|
||||||
default from: "no-reply@#{domain}"
|
default from: "no-reply@#{domain}"
|
||||||
|
|
||||||
def new(comment_id, to)
|
def born(comment_id, to)
|
||||||
@comment = Comment.find(comment_id)
|
@comment = Comment.find(comment_id)
|
||||||
mail to: to, subject: '博主, 你的博客有新的评论'
|
mail to: to, subject: '博主, 你的博客有新的评论'
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ class PostMailer < ActionMailer::Base
|
||||||
|
|
||||||
default from: "no-reply@#{domain}"
|
default from: "no-reply@#{domain}"
|
||||||
|
|
||||||
def new(post_id, to)
|
def born(post_id, to)
|
||||||
@post = Post.find(post_id)
|
@post = Post.find(post_id)
|
||||||
mail to: to, subject: '客官, 新博客来了'
|
mail to: to, subject: '客官, 新博客来了'
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,10 +7,10 @@ class Comment < ApplicationRecord
|
||||||
validates :content, presence: true
|
validates :content, presence: true
|
||||||
|
|
||||||
def reply_emails
|
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
|
end
|
||||||
|
|
||||||
after_create do
|
after_commit on: :create do
|
||||||
if ENV['MAIL_SERVER'].present? && ENV['ADMIN_USER'].present? && ENV['ADMIN_USER'] =~ /@/
|
if ENV['MAIL_SERVER'].present? && ENV['ADMIN_USER'].present? && ENV['ADMIN_USER'] =~ /@/
|
||||||
Rails.logger.info 'comment created, comment worker start'
|
Rails.logger.info 'comment created, comment worker start'
|
||||||
NewCommentWorker.perform_async(self.id.to_s, ENV['ADMIN_USER'])
|
NewCommentWorker.perform_async(self.id.to_s, ENV['ADMIN_USER'])
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Post < ActiveRecord::Base
|
||||||
validates :title, :presence=>true, :uniqueness=> true
|
validates :title, :presence=>true, :uniqueness=> true
|
||||||
validates :content, :presence=>true, :length => { :minimum=> 30 }
|
validates :content, :presence=>true, :length => { :minimum=> 30 }
|
||||||
|
|
||||||
after_create do
|
after_commit on: :create do
|
||||||
if ENV['MAIL_SERVER'].present?
|
if ENV['MAIL_SERVER'].present?
|
||||||
NewPostWorker.perform_async(self.id.to_s)
|
NewPostWorker.perform_async(self.id.to_s)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
h1 Unsubscribes#create
|
|
||||||
p Find me in app/views/unsubscribes/create.html.slim
|
|
|
@ -7,7 +7,7 @@ class NewCommentWorker
|
||||||
|
|
||||||
def perform(comment_id, to)
|
def perform(comment_id, to)
|
||||||
logger.info "new comment mail: #{comment_id}"
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ class NewPostWorker
|
||||||
def perform(post_id)
|
def perform(post_id)
|
||||||
Subscribe.subscribe_list.each do |email|
|
Subscribe.subscribe_list.each do |email|
|
||||||
Rails.logger.info "new post #{post_id}, send to #{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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,6 @@ class NewReplyPostWorker
|
||||||
logger.info "new reply mail"
|
logger.info "new reply mail"
|
||||||
comment = Comment.find(comment_id.to_s)
|
comment = Comment.find(comment_id.to_s)
|
||||||
comment.reply_emails.each do |email|
|
comment.reply_emails.each do |email|
|
||||||
next if email == ENV['ADMIN_USER']
|
|
||||||
logger.info "new reply mail to #{email}"
|
logger.info "new reply mail to #{email}"
|
||||||
CommentMailer.reply(comment_id.to_s, email).deliver
|
CommentMailer.reply(comment_id.to_s, email).deliver
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ WBlog::Application.configure do
|
||||||
# number of complex assets.
|
# number of complex assets.
|
||||||
config.assets.debug = true
|
config.assets.debug = true
|
||||||
|
|
||||||
config.middleware.insert_before 0, "Rack::Cors" do
|
config.middleware.insert_before 0, Rack::Cors do
|
||||||
allow do
|
allow do
|
||||||
origins '*'
|
origins '*'
|
||||||
resource '*', :headers => :any, :methods => [:get, :post, :options]
|
resource '*', :headers => :any, :methods => [:get, :post, :options]
|
||||||
|
|
Loading…
Reference in New Issue