Skip to content

Instantly share code, notes, and snippets.

@willrjmarshall
Created October 19, 2011 04:11
Show Gist options
  • Save willrjmarshall/1297460 to your computer and use it in GitHub Desktop.
Save willrjmarshall/1297460 to your computer and use it in GitHub Desktop.
# Rails 3.X Template
if defined?(Rails) && Rails.version =~ /^3/
module ActionView
module Template::Handlers
class Rabl
class_attribute :default_format
self.default_format = Mime::JSON
def self.call(template)
source = if template.source.empty?
File.read(template.identifier)
else # use source
template.source
end
%{ ::Rabl::Engine.new(#{source.inspect}, { :format => "json"}).
render(self, assigns.merge(local_assigns)) }
end # call
end # rabl class
end # handlers
end
ActionView::Template.register_template_handler :rabl, ActionView::Template::Handlers::Rabl
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment