-
-
Save jamesarosen/193705 to your computer and use it in GitHub Desktop.
using plain ole' Ruby as a Rails TemplateHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
require 'rb_template_handler' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@people.map do |person| | |
suggestion = person.full_name | |
data = { :id => person.id }.to_json | |
"#{suggestion}|#{data}" | |
end.join("\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mime::Type.register_alias "text/plain", :jqa # JQuery Autocomplete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PeopleController < ActionController::Base | |
def index | |
respond_to do |format| | |
format.jqa | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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