我已经在我的应用程序中设置了行动邮件发送给微博用户一封邮件,每当一个新的评论已经在他的微博上。
这是我的密码
comments_controller
def create
@micropost = Micropost.find(params[:micropost_id])
@comment = Comment.new(params[:comment].permit(:user_id, :body, :micropost_id))
@comment.micropost = @micropost
@comment.micropost.user = @micropost.user
@comment.user = current_user
if @comment.save
UserMailer.newcomment_email(@comment).deliver
@comment.create_activity :create, owner: current_user
flash[:success] = "Comment created!"
redirect_to @micropost
else
render 'shared/_comment_form'
end
enduser_mailer.rb
class UserMailer < ActionMailer::Base
default from: "deppy007@gmail.com"
def newcomment_email(comment)
@comment = comment
mail(to: comment.micropost.user.email, subject: "New Comment Notify")
end
endnewcomment_email.html.erb
<%= @comment.user.username %> commented on your post <%= "micropost link?" %>
<p>comment: <%= @comment.body %></p> 代码运行良好,并向微博用户发送邮件提示,表示用户对您的帖子进行了评论。那么我该如何将微博链接放到电子邮件中呢?
发布于 2015-02-10 00:53:55
在您的邮件程序(即newcomment_email.html.erb )的视图中,向注释添加一个link_to标记。例如:
<%= link_to 'micropost', micropost_url(@comment.micropost) %>这只是一个例子。根据您的应用程序更改它。它就能达到要求。希望这能有所帮助。
发布于 2015-02-10 14:02:48
然后添加您的routes.rb
Your::Application.routes.draw do
default_url_options :host => "www.example.com"
end添加应用程序域名将使用户重定向到存在于微博上的站点。
https://stackoverflow.com/questions/28422222
复制相似问题