在rails应用程序中手动发送特定页面的电子邮件 [英] Send an email manually of a specific page in rails app

查看:239
本文介绍了在rails应用程序中手动发送特定页面的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的应用程序,每季度为客户收集储蓄数据。与其他具有图表和图表的客户端数据相比,可以显示每个客户端的数据。我正在寻找一个简单的方法来实现一个按钮(或某些东西),让我可以手动地将该视图发送到客户端,并以html的形式发送给我。我只看到教程,显示如何在注册或确认类型的电子邮件时发送电子邮件。

I have a basic application that gathers savings data for clients each quarter. There is a view that shows this data for each client compared to other client data with charts and graphs. I'm looking for an easy way to implement a button (or something) that allows me to manually send that view to the client in an html email at my discretion. I have only found tutorials showing how to send emails upon registration or confirmation type emails.

推荐答案

# app/mailers/user_mailer.rb
class UserMailer < ActionMailer
  def report
    @things = Thing.report_stuff
    mail :to => 'boss@example.com', :from => 'you@example.com', 
      :subject => 'that report you want'
  end
end

# app/views/user_mailer/report.html.erb
<h1>Report</h1>
<% @things.each do |thing| %>
  <%= thing.name %>
<% end %> 

# app/controllers/reports_controller.rb
def create
  UserMailer.report.deliver
  flash[:notice] = 'report sent!'
  redirect_to root_path # or wherever
end

# in a view
<% form_tag(reports_path, :method => :post) do %>
  <% submit_tag 'send report email' %>
<% end %>

这篇关于在rails应用程序中手动发送特定页面的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆