0

In my application , I have to attach the excel and pdf but it is throughing an error .

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:

Below is my controller code -

def show_self_datewise_attendance
    @from = params[:employee][:from]
    @to = params[:employee][:to]
    @employee_attendances = EmployeeAttendance.where(day: @from.to_date..@to.to_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
Anubhi Golechha
  • 167
  • 2
  • 14

1 Answers1

0

What does your self_services/datewise_attendance_report_xls.xls.erb actually look like? According to the error you posted the file cannot be found. I have followed this successfully in the past without issue http://railscasts.com/episodes/362-exporting-csv-and-excel.

a2f0
  • 1,615
  • 2
  • 19
  • 28
  • datewise_attendance_report_xls.xls.erb is a excel page which is in the self_service table . – Anubhi Golechha May 11 '17 at 11:08
  • As far as I know it has to be a file on the filesystem. Do you have a view template (i.e. a file) that exists at that path? Also, FWIW, I get this to work without a template (just a view). – a2f0 May 11 '17 at 11:12
  • You may have to use `Mime::Type.register "application/xls", :xls` to do this without a template (as per the Railscast from above). – a2f0 May 11 '17 at 11:19