我有两个使用 Prawn PDF “即时”制作的 PDF。
PDF 文件称为 jobsheet.pdf 和 dispatch.pdf - 它们的 URL 是:
railsroot/kases/IDNO/jobsheet.pdf
railsroot/kases/IDNO/discharge.pdf
我正在尝试解决如何自动将文件名附加到 ID 号:
railsroot/kases/IDNO/jobsheet_IDNO.pdf
railsroot/kases/IDNO/discharge_IDNO.pdf
要创建 PDF,代码如下:
卡西斯控制器
def jobsheet
@kase = Kase.find(params[:id])
respond_to do |format|
format.html {} # jobsheet.html.erb
format.xml { render :xml => @kase }
format.pdf { render :layout => false }
prawnto :prawn => {
:background => "#{RAILS_ROOT}/public/images/jobsheet.png",
:left_margin => 0,
:right_margin => 0,
:top_margin => 0,
:bottom_margin => 0,
:page_size => 'A4' }
end
end
# GET /kases/1
# GET /kases/1.xml
def discharge
@kase = Kase.find(params[:id])
respond_to do |format|
format.html { } # discharge.html.erb
format.xml { render :xml => @kase }
format.pdf { render :layout => false }
prawnto :prawn => {
:background => "#{RAILS_ROOT}/public/images/discharge.png",
:left_margin => 0,
:right_margin => 0,
:top_margin => 0,
:bottom_margin => 0,
:page_size => 'A4' }
end
end
路线
map.resources :kases, :member => { :discharge => :get }
map.resources :kases, :member => { :jobsheet => :get }
要查看 PDF,我使用以下链接:
jobsheet_kase_path(@kase, :format => 'pdf')
discharge_kase_path(@kase, :format => 'pdf')
这甚至可能吗?
谢谢,
丹尼