2014-02-24 44 views
1

我正在寫一個類來編寫名爲「BravoManagementXlsReport」的XLS文件。它目前坐在以下目錄:對象無法找到後代?

enter image description here

所有其他報告都來自xls_report繼承,所以我也一樣。

class BravoManagementXlsReport < XlsReport 
    attr_reader :file_name 
    ... 
end 

當我運行工人,我得到:

2014-02-24T16:22:58Z 18204 TID-ovbv17qdg WARN: uninitialized constant BravoManagementXlsReport 

,我想我應該重新啓動工人,但沒有工作,所以我重新啓動Rails服務器,但沒有任何工作。在控制檯我嘗試過:

[2] toolkit » ManagementXlsReport // this returns the object 
=> ManagementXlsReport < XlsReport 
[3] toolkit » BravoManagementXlsReport // this is obviously not finding it 
NameError: uninitialized constant BravoManagementXlsReport 

[1] toolkit » XlsReport.descendants // this returns everything but the new file 
=> [ 
    [0] SocioeconomicDevelopmentXlsReport < XlsReport, 
    [1] EnterpriseDevelopmentXlsReport < XlsReport, 
    [2] PreferentialProcurementXlsReport < XlsReport, 
    [3] IntermediaryBillXlsReport < XlsReport, 
    [4] ScorecardXlsReport < XlsReport, 
    [5] TrainingProgramXlsReport < XlsReport, 
    [6] GeneralXlsReport < XlsReport, 
    [7] EmploymentEquityXlsReport < XlsReport, 
    [8] ManagementXlsReport < XlsReport, 
    [9] SkillsDevelopmentXlsReport < XlsReport 
] 

有什麼我失蹤?我試着看看我是否有拼寫錯誤,但我看不到它。

+0

也許嘗試對其他報告之一進行項目範圍搜索,看看是否需要首先在某處註冊它。我真的可以推薦[ack](http://beyondgrep.com/)來搜索代碼。例如,你可以執行'ack -i ManagementXlsReport'並查看除了類定義本身以外是否還有結果。 –

+0

是的,我做了一個全系統的搜索,以防萬一有安全功能的東西。在規格中只有其他地方的後代被稱爲。 – TheLegend

+0

您還可以搜索文件名,以防需要在其他地方需要報告。 –

回答

0

我終於知道發生了什麼事。路徑沒有被軌道加載。在應用程序配置文件中,我找到了這個。我認爲它只是糟糕的遺留代碼,讓我感到困惑。

# These are imported so that the elements are downloadable to excel 
require "#{Rails.root}/lib/reports/xls_report.rb" 
[:employment_equity, :management, :skills_development, :enterprise_development, :preferential_procurement, :socioeconomic_development, :general, :training_program, :scorecard, :intermediary_bill].each do |file| 
    require "#{Rails.root}/lib/reports/#{file}_xls_report.rb" 
end 

所以我只是用自動路徑裝載機替代它:

config.autoload_paths += %W(#{Rails.root}/lib/reports) 

現在它工作得很好:)非常感謝你的幫助的!希望這最終會幫助別人。