Skip to content

Instantly share code, notes, and snippets.

@jkeck
Created September 20, 2011 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkeck/1229804 to your computer and use it in GitHub Desktop.
Save jkeck/1229804 to your computer and use it in GitHub Desktop.
Blacklight.configure(:shared) do |config|
#...
SolrDocument.use_extension(YourModule)
#...
end
class YourController < ApplicationController
def my_json
response, @document = get_solr_response_for_doc_id
render :text => @document.my_json, :layout => false
end
def our_json
response, @document = get_solr_response_for_doc_id
render :text => @document.export_as(:our_json), :layout => false
end
end
module YourModule
# This is the simplest implementation
def my_json
return {:this_is_my_json => ["Thing1","Thing2"]}.to_json
end
# This uses the export_as functionality. This will make the JSON a true export format which will be auto-discoverable.
def self.extended(document)
document.export_as(:our_json,"application/json")
end
private
def export_as_our_json
return {:this_is_our_json => ["Thing1","Thing2"]}.to_json
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment