Skip to content

Instantly share code, notes, and snippets.

@rwz
Created August 7, 2012 05:35
Show Gist options
  • Save rwz/3281979 to your computer and use it in GitHub Desktop.
Save rwz/3281979 to your computer and use it in GitHub Desktop.
Rendering Jbuilder templates from within model
# 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
@Vetal4eg
Copy link

Vetal4eg commented Oct 4, 2012

Nice! But... I would't use it in the model. This is awsme for library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment