0

I'm building an app wherein I want to parse bibtex into citations in html. I used the CiteProc-Ruby and bibtex-ruby gems to implement this.

I used this gem. I tried the following code in the Rails console.

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

This works fine. The cp object is a hash of references parsed from the sources.bib file, and with this has I can render html citations in APA or some other format.

So now I want to use this in my app. So I added this to 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 

My expectation was to use the @cp object in the views. But instead I get this error message:

uninitialized constant ApplicationController::CiteProc

What is the correct way to do this?

Count Zero
  • 630
  • 1
  • 6
  • 15

1 Answers1

0

require 'citeproc' should do it. Generally just adding citeproc to your Gemfile should require it (assuming you're using a default Rails setup)

Josh Bodah
  • 1,223
  • 6
  • 17