https://github.com/hopsoft/self_renderer
Rails model & object rendering outside the context of web requests
https://github.com/hopsoft/self_renderer
ruby ruby-on-rails server-side-rendering
Last synced: about 1 month ago
JSON representation
Rails model & object rendering outside the context of web requests
- Host: GitHub
- URL: https://github.com/hopsoft/self_renderer
- Owner: hopsoft
- License: mit
- Created: 2017-04-12T17:37:53.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-04T22:28:48.000Z (over 7 years ago)
- Last Synced: 2025-03-01T00:54:46.920Z (2 months ago)
- Topics: ruby, ruby-on-rails, server-side-rendering
- Language: Ruby
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
[](https://codeclimate.com/github/hopsoft/self_renderer)
[](https://gemnasium.com/hopsoft/self_renderer)# SelfRenderer
Rails model & object rendering outside the context of web requests.
## Use Cases
* Serialize model in background job to send over ActionCable
* etc....## Quick Start
```ruby
# Gemfile
gem "self_renderer"
``````ruby
# app/models/user.rb
class User < ApplicationRecord
include SelfRenderer
end
``````erb
User
<%= render "item" %>
``````erb
<%= @user.name %>
``````ruby
# app/views/users/show.json.jbuilder
json.partial! "item"
``````ruby
# app/views/users/_item.json.jbuilder
json.name @user.name
``````ruby
# render html strings
User.find(1).render_with(template: "users/show.html")
User.find(2).render_with(partial: "users/item.html")# render json strings
User.find(3).render_with(template: "users/show.json")
User.find(4).render_with(partial: "users/item.json")# render ruby hashes
User.find(5).render_to_hash(template: "users/show.json")
User.find(6).render_to_hash(partial: "users/item.json")
```