2017-05-11 35 views
0

在我的應用程序中,我必須附加excel和pdf,但它是通過一個錯誤。Excel和Pdf不能在RoR中工作

ActionView::MissingTemplate: Missing template self_services/show, application/show with {:locale=>[:en], :formats=>[:xls], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :axlsx, :jbuilder]}. Searched in: 

下面是我的控制器代碼 -

def show_self_datewise_attendance 
    @from = params[:employee][:from] 
    @to = params[:employee][:to] 
    @employee_attendances = EmployeeAttendance.where(day: @[email protected]_date,employee_id: current_user.employee_id) 

    respond_to do |format| 
     format.js 
     format.xls {render template: 'self_services/datewise_attendance_report_xls.xls.erb'} 
     format.html 
     format.pdf do 
     render pdf: 'datewise_attendance_report_pdf', 
       layout: 'pdf.html', 
       orientation: 'Landscape', 
       template: 'self_services/datewise_attendance_report_pdf.pdf.erb', 
       # show_as_html: params[:debug].present?, 
       :page_height  => 1000, 
       :dpi    => '300', 
       :margin   => {:top => 10, # default 10 (mm) 
          :bottom => 10, 
          :left => 20, 
          :right => 20}, 
       :show_as_html => params[:debug].present? 
      end 
     end 
    end 
+0

試試這個希望它會工作http://stackoverflow.com/questions/9561000/actionviewmissingtemplate-missing-template –

+0

到目前爲止,你有任何解決方案? –

+0

還沒有@AniketShivamTiwari –

回答

0

什麼是您的self_services/datewise_attendance_report_xls.xls.erb實際上是什麼樣子?根據您發佈的錯誤找不到該文件。我過去沒有問題http://railscasts.com/episodes/362-exporting-csv-and-excel成功地跟蹤了這個問題。

+0

datewise_attendance_report_xls.xls.erb是一個excel頁面,位於self_service表中。 –

+0

據我所知它必須是文件系統上的文件。你有一個存在於該路徑的視圖模板(即文件)嗎?此外,FWIW,我得到這個工作沒有模板(只是一個看法)。 – dps

+0

您可能必須使用'Mime :: Type.register「application/xls」,:xls'才能在沒有模板的情況下執行此操作(按照上面的Railscast)。 – dps