2016-01-20 64 views
0

我正在構建一個應用程序,其中我想將bibtex解析爲html中的引用。我用CiteProc-Rubybibtex-ruby寶石來實現這一點。Rails中的Bibtex解析器;可以讓寶石在控制檯中工作,但不是應用程序本身

我用這個寶石。我在Rails控制檯中嘗試了以下代碼。

cp = CiteProc::Processor.new style: 'apa', format: 'text' 
cp.import BibTeX.open('sources.bib').to_citeproc 

這工作正常。 cp對象是從sources.bib文件中解析的引用的散列,並且可以使用APA或其他格式呈現html引用。

所以現在我想在我的應用程序中使用它。所以我把它添加到application_controller.rb

class ApplicationController < ActionController::Base 
    protect_from_forgery with: :exception 
    @cp = CiteProc::Processor.new style: 'apa', format: 'text' 
    @cp.import BibTeX.open('sources.bib').to_citeproc 
end 

我的期望是在視圖中使用@cp對象。而是我得到這個錯誤信息:

未初始化的常量的ApplicationController :: CiteProc

什麼是做這種正確的方法是什麼?

回答

0

require 'citeproc'應該這樣做。通常只需將citeproc添加到Gemfile中就可以了(假設您使用默認的Rails設置)

相關問題