Last active
August 29, 2015 13:58
-
-
Save kainosnoema/10012517 to your computer and use it in GitHub Desktop.
Jsonite in Rails using Ruby ActionView Template Handler
This file contains 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
# config/initializers/rb_template_template.rb | |
class RbTemplateHandler | |
cattr_accessor :default_format | |
self.default_format = Mime::JSON | |
def self.call(template) | |
%{rendered = begin;#{template.source};end | |
unless rendered.is_a?(String) | |
rendered = rendered.to_#{template.type.to_sym} | |
end | |
rendered} | |
end | |
end | |
ActionView::Template.register_template_handler :rb, RbTemplateHandler | |
This file contains 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
UserPresenter.present @user, root: 'user' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment