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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
# 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 %>