2014-06-05 34 views
1

我有這樣Axlsx-Rails的寶石不能正常工作,顯示缺少模板

<%= link_to "download file", import_horse_report_horses_path(format: 'xlsx') %> 

一個鏈接,然後在控制器動作我有以下代碼

def import_horse_report 
    @horses = ImportHorse.all   
    respond_to do |format| 
     format.xlsx{ } 
    end 
    end 

對於這個動作我有這個模板import_horse_report.xlsx.axlsx

wb = xlsx_package.workbook 
wb.add_worksheet(name: "Horses") do |sheet| 
    @horses.each do |horse| 
    sheet.add_row [horse.breed, horse.date_of_birth, horse.gender] 
    end 
end 

我使用axlsx_rails寶石並按照其文檔。但我得到這個錯誤

Missing template horses/import_horse_report, application/import_horse_report with {:locale=>[:en], :formats=>[:xlsx], :handlers=>[:erb, :builder, :coffee, :rabl]} 

我該如何解決這個問題?

+0

您保存了這個'import_horse_report.xlsx.axlsx'模板的位置?路徑? –

+0

在這個控制器的其他動作的視圖 – asdfkjasdfjk

+0

讓我的路徑 –

回答

0

嘗試一個明確的渲染聲明:

format.xlsx { render xlsx: 'import_horse_report' } 

如果您在調用/horses/import_horse_report而沒有結尾.xlsx,則除非您在路由文件中強制使用:xlsx格式,否則不會執行渲染語句。如果您想保留respond_to區塊,請更改您的網址。否則,你可以刪除respond_to塊一個簡單的render :xlsx語句(前提是你永遠不會投放任何東西。)

+0

有一個非常簡單的可能性。你在叫'/ horses/import_horse_report.xlsx'還是'/ horses/import_horse_report'?如果是後者,則不會在不使用'routes'強制格式的情況下找到模板。 – noel

+0

編輯我的答案。 – noel

0

我用

render xlsx: "import_horse_report" 

,而不是固定的respond_to這個。這可能是一個選項,取決於你的情況。