Created
August 7, 2012 05:35
-
-
Save rwz/3281979 to your computer and use it in GitHub Desktop.
Rendering Jbuilder templates from within model
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
# this is the easiest way to use partials from model I could find so far | |
class Entry < AR::Base | |
def as_json | |
context = ApplicationController.new.view_context | |
context.render('/api/entries/entry.json', entry: self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! But... I would't use it in the model. This is awsme for library.