Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
Forked from technicalpickles/example.json.rb
Created September 25, 2009 17:45
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 jamesarosen/193705 to your computer and use it in GitHub Desktop.
Save jamesarosen/193705 to your computer and use it in GitHub Desktop.
using plain ole' Ruby as a Rails TemplateHandler
...
require 'rb_template_handler'
@people.map do |person|
suggestion = person.full_name
data = { :id => person.id }.to_json
"#{suggestion}|#{data}"
end.join("\n")
Mime::Type.register_alias "text/plain", :jqa # JQuery Autocomplete
class PeopleController < ActionController::Base
def index
respond_to do |format|
format.jqa
end
end
end
class RbTemplateHandler < ActionView::TemplateHandler
include ActionView::TemplateHandlers::Compilable if defined?(ActionView::TemplateHandlers::Compilable)
def compile(template)
template.source
end
end
ActionView::Template.register_template_handler(:rb, RbTemplateHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment