Mandrill API 未发送
Mandrill API not sending
我正在尝试将 Mandrill API 设置为在用户单击按钮时发送电子邮件,但我似乎无法发送它。电子邮件将从控制台发送得很好,所以我知道这不是模板的问题(设计电子邮件也发送查找)。
我认为这与我在控制器中的设置方式有关,但我找不到任何关于我应该把它放在哪里的帮助。
这是来自控制器的代码:
def attending
@event = Event.find(params[:id])
type = params[:type]
if type == "attending" && @event.space != 0
current_user.attending << @event
@event.space = @event.space - 1
@event.save
AdminMailer.new_attending(@event.user, current_user)
redirect_to :back, notice: "You've joined the group. Your number will be sent to #{@event.user.name}"
else type == "unattending"
current_user.attending.delete(@event)
redirect_to :back, notice: "You've removed yourself from the group"
end
end
这是admin_mailer.rb
class AdminMailer < ActionMailer::Base
require 'mandrill'
def mandrill_client
@mandrill_client ||= Mandrill::API.new MANDRILL_API_KEY
end
def new_attending(creator, user)
template_name = "new-attending"
template_content = []
message = {
to: [{email: creator.email, name: creator.name}],
subject: "Someone wants to go riding with you!",
merge_vars: [
{rcpt: creator.email,
vars: [
{name: "CREATOR_NAME", content: creator.name},
{name: "USER_NAME", content: user.name},
{name: "USER_NUMBER", content: user.number}
]}
]
}
mandrill_client.messages.send_template template_name, template_content, message
end
end
这是他们在应该发送电子邮件的 view.html.erb 中单击的 link:
<td><% if event.user != current_user && event.space != 0 && user_signed_in? %>
<% unless event.attendees.include?(current_user) %>
<%= link_to "Join", attending_event_path(event, type: "attending"), class: "btn btn-primary btn-xs", method: :put %>
<% end %>
<% end %></td>
如果能帮助您找出未发送的原因,那就太好了!正如我所说,当我输入时它在控制台中工作:
AdminMailer.new_attending(@event, @user)
请替换以下代码。
AdminMailer.new_attending(@event.user, current_user)
和
AdminMailer.new_attending(@event.user, current_user).deliver
我希望这会奏效。
我正在尝试将 Mandrill API 设置为在用户单击按钮时发送电子邮件,但我似乎无法发送它。电子邮件将从控制台发送得很好,所以我知道这不是模板的问题(设计电子邮件也发送查找)。
我认为这与我在控制器中的设置方式有关,但我找不到任何关于我应该把它放在哪里的帮助。
这是来自控制器的代码:
def attending
@event = Event.find(params[:id])
type = params[:type]
if type == "attending" && @event.space != 0
current_user.attending << @event
@event.space = @event.space - 1
@event.save
AdminMailer.new_attending(@event.user, current_user)
redirect_to :back, notice: "You've joined the group. Your number will be sent to #{@event.user.name}"
else type == "unattending"
current_user.attending.delete(@event)
redirect_to :back, notice: "You've removed yourself from the group"
end
end
这是admin_mailer.rb
class AdminMailer < ActionMailer::Base
require 'mandrill'
def mandrill_client
@mandrill_client ||= Mandrill::API.new MANDRILL_API_KEY
end
def new_attending(creator, user)
template_name = "new-attending"
template_content = []
message = {
to: [{email: creator.email, name: creator.name}],
subject: "Someone wants to go riding with you!",
merge_vars: [
{rcpt: creator.email,
vars: [
{name: "CREATOR_NAME", content: creator.name},
{name: "USER_NAME", content: user.name},
{name: "USER_NUMBER", content: user.number}
]}
]
}
mandrill_client.messages.send_template template_name, template_content, message
end
end
这是他们在应该发送电子邮件的 view.html.erb 中单击的 link:
<td><% if event.user != current_user && event.space != 0 && user_signed_in? %>
<% unless event.attendees.include?(current_user) %>
<%= link_to "Join", attending_event_path(event, type: "attending"), class: "btn btn-primary btn-xs", method: :put %>
<% end %>
<% end %></td>
如果能帮助您找出未发送的原因,那就太好了!正如我所说,当我输入时它在控制台中工作:
AdminMailer.new_attending(@event, @user)
请替换以下代码。
AdminMailer.new_attending(@event.user, current_user)
和
AdminMailer.new_attending(@event.user, current_user).deliver
我希望这会奏效。