我正在尝试使用ActionMailer和wicked_pdf生成带有渲染PDF附件的电子邮件.
在我的网站上,我已经分别使用了wicked_pdf和actionmailer.我可以使用wicked_pdf在Web应用程序中提供pdf,并可以使用ActionMailer发送邮件,但是我无法将呈现的pdf内容附加到ActionMailer(针对内容进行编辑):
class UserMailer < ActionMailer::Base
default :from => "webadmin@mydomain.com"
def generate_pdf(invoice)
render :pdf => "test.pdf",
:template => 'invoices/show.pdf.erb',
:layout => 'pdf.html'
end
def email_invoice(invoice)
@invoice = invoice
attachments["invoice.pdf"] = {:mime_type => 'application/pdf',
:encoding => 'Base64',
:content => generate_pdf(@invoice)}
mail :subject => "Your Invoice", :to => invoice.customer.email
end
end
Run Code Online (Sandbox Code Playgroud)
使用Railscasts 206(Rails 3中的Action Mailer)作为指南,只有在我不尝试添加渲染的附件时,我才能发送包含我所需的丰富内容的电子邮件.
如果我尝试添加附件(如上所示),我会看到一个看起来正确大小的附件,只有附件的名称没有按预期发现,也不能作为pdf读取.除此之外,我的电子邮件内容丢失了......
有没有人在使用Rails 3.0动态渲染PDF时有使用ActionMailer的经验?
提前致谢! - 担
我一直在使用Wicked_pdf将视图呈现为PDF和动作管理器来发送电子邮件,但我不能让它们一起工作.我想使用actionmailer将特定视图的PDF版本附加到电子邮件中,然后通过单击链接或按钮将其发送出去.我有一个发送电子邮件的link_to命令.这是我的控制器获取生成的电子邮件:
def sendemail
@user = User.find(params[:id])
Sendpdf.send_report(@user).deliver
redirect_to user_path(@user)
flash[:notice] = 'Email has been sent!'
end
Run Code Online (Sandbox Code Playgroud)
这是我在动作管理器中的内容:
class Sendpdf < ActionMailer::Base
default :from => "myemail@email.com"
def send_report(user)
@user = user
attachment "application/pdf" do |a|
a.body = #Something should go here, maybe WickedPDF.new.something?
a.filename = 'MyPDF'
end
mail(:to => user.email, :subject => "awesome pdf, check it")
end
end
Run Code Online (Sandbox Code Playgroud)
我见过很多问题和答案,大多数都与Prawn打交道.似乎应该有一个简单的答案.有人可以帮忙吗?
更新我很感激在下面的答案中使用建议作为替代选项.但是,我真的想学习如何将视图呈现为PDF并将其附加到我的电子邮件中.如果需要,我愿意使用像Prawn或其他任何东西一样的东西.
pdf-generation ruby-on-rails actionmailer ruby-on-rails-3 wicked-pdf
我正在使用本指南在heroku上集成wicked_pdf.但不知何故它似乎不起作用.我从heroku获得了日志,它说:
Processing PdfController#get_pdf to pdf (for 115.248.175.50 at 2011-02-15 23:54:44) [GET]
Parameters: {"format"=>"pdf", "action"=>"get_pdf", "id"=>"1", "controller"=>"pdf"}
***************WICKED***************
Rendering pdf/get_pdf
RuntimeError (PDF could not be generated!
/usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `exec': No such file or directory - /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/bin/wkhtmltopdf-amd64 - - (Errno::ENOENT)
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `popen3'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `fork'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `popen3'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `fork'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `popen3'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/wicked_pdf.rb:22:in `pdf_from_string'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:28:in `make_pdf'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:39:in `make_and_send_pdf'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:13:in `render'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/app/controllers/schedule_controller.rb:33:in `get_pdf'
Run Code Online (Sandbox Code Playgroud)
请帮忙.提前致谢.
编辑:
我在代码中做了一些更改并完成了这个错误,但仍然停留在这里
NoMethodError (undefined method empty? for #<Pathname:0x2b7112392480>)
pdf-generation ruby-on-rails heroku production-environment wicked-pdf
我正在尝试使用PDFKit作为rails 3应用程序中的中间件.
我可以从命令行使用wkhtmltopdf就好了,但是我的应用程序一直让我犯这个错误
command failed: "/Users/bobby/.rvm/gems/ruby-1.9.2-p0/bin/wkhtmltopdf" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-right" "0.75in" "--margin-bottom" "0.75in" "--margin-left" "0.75in" "--encoding" "UTF-8" "--print-media-type" "--quiet" "-" "-"
Run Code Online (Sandbox Code Playgroud)
如果我在终端运行它,它等待我的输入,所以我键入一些HTML,然后按Ctrl-d,它吐出似乎是一些PDF ...但没有运气轨道.
这就是我所拥有的:
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require 'pdfkit'
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Mpr
class Application < Rails::Application
YEARS_ARRAY = (2006..2012).map {|y| [y,y]}.unshift(["Year",nil])
MONTHS_ARRAY = (1..12).map{|m| [ Date::MONTHNAMES[m], m]}.unshift(["All months",nil])
config.middleware.use "PDFKit::Middleware", :print_media_type => true
PDFKit.configure do |config|
config.wkhtmltopdf = '/Users/bobby/.rvm/gems/ruby-1.9.2-p0/bin/wkhtmltopdf'
end
end
end
Run Code Online (Sandbox Code Playgroud)
在我的控制器(第一行)
respond_to :html, :pdf
Run Code Online (Sandbox Code Playgroud)
我想我已经浏览了SO,Github和谷歌的所有主题,但没有运气.
任何人都可以帮助或指出我正确的方向吗?
谢谢,P
我想使用命令行将文件名列表输出到 CSV,但文件位于网络驱动器上。
在我的电脑上,我的 D: 驱动器上有一个电影文件夹。通过在命令行中更改目录并使用,dir /b > Movies.csv我可以获得该目录中所有电影片名的列表。但是,我们现在有一个 WD NAS 盒子,里面有我们所有的电影,我想以某种方式使用命令行从中提取更新的电影名称 csv。由于它不再位于我计算机中的一个驱动器上,因此我不确定如何执行此操作。
我需要问我的用户是否会使用信用卡支付服务...如果它选中了pay_with_card选项?它必须显示表格的其余部分,要求其他数据,如卡号,邮件等,如果用户没有检查它,它必须显示一条消息,问题是......我该怎么做?提前致谢
<%= form_for(@product) do |f| %>
<%= f.label :pay_with_card? %>
<%= f.check_box :pay_with_card,{}, "Yes", "No"%>
<div>
<%= f.label :card_number %> <%= f.text_field :card_number %>
</div>
<div>
<%= f.label :mail %> <%= f.text_field :mail %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud) wicked-pdf ×3
actionmailer ×2
checkbox ×1
command-line ×1
forms ×1
heroku ×1
pdfkit ×1
windows ×1
wkhtmltopdf ×1