# Render partial from model?

**URL:** <https://www.ruby-forum.com/t/render-partial-from-model/136088>\
**Category:** Rails\
**Created:** [April 28, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/render-partial-from-model/136088 "2008-04-28T21:06:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [April 28, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/render-partial-from-model/136088/1 "2008-04-28T21:06:01Z")

</div>

Hi,

I know that this goes against MVC, but is there any way to render a  
partial from a model? The reason for me wanting to do this is that the  
caching logic is quite complex and I would like to keep it in the model.

Thanks,  
GiantCranes

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [April 28, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/render-partial-from-model/136088/2 "2008-04-28T21:18:29Z")

</div>

On Apr 28, 8:06 pm, Giant C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> I know that this goes against MVC, but is there any way to render a  
> partial from a model? The reason for me wanting to do this is that the  
> caching logic is quite complex and I would like to keep it in the model.

Not in a month of mondays. Cache sweepers may be of interest to you.

Fred

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [April 28, 2008, 10:48pm UTC](https://www.ruby-forum.com/t/render-partial-from-model/136088/3 "2008-04-28T22:48:50Z")

</div>

Frederick C. wrote:

> On Apr 28, 8:06ï¿½pm, Giant C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi,
> > 
> > I know that this goes against MVC, but is there any way to render a  
> > partial from a model? The reason for me wanting to do this is that the  
> > caching logic is quite complex and I would like to keep it in the model.
> 
> Not in a month of mondays. Cache sweepers may be of interest to you.
> 
> Fred

Thanks, I’ll take a look.

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [April 29, 2008, 4:29am UTC](https://www.ruby-forum.com/t/render-partial-from-model/136088/4 "2008-04-29T04:29:54Z")

</div>

Frederick C. wrote:

> Not in a month of mondays.  
> Except if you use Builder::XmlMarkup to generate arbitrary XHTML in the  
> model,  
> forsaking the helpers like h() that the vi

> Cache sweepers may be of interest to you.

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [April 29, 2008, 4:36am UTC](https://www.ruby-forum.com/t/render-partial-from-model/136088/5 "2008-04-29T04:36:27Z")

</div>

Frederick C. wrote:

> Giant C. wrote:

> > I know that this goes against MVC, but is there any way to render a  
> > partial from a model? The reason for me wanting to do this is that  
> > the
> 
> > caching logic is quite complex and I would like to keep it in the  
> > model.
> 
> > 
> 
> Not in a month of mondays.

Except if you use Builder::XmlMarkup to generate arbitrary XHTML in the  
model,  
forsaking the helpers like h() that the View give you. And-or if you  
build  
arbitrary strings that your controller won’t mind calling render :inline  
=\> on.

> Cache sweepers may be of interest to you.

Ayup. There are perfectly MVC reasons to concoct HTML in the Model. The  
faintest  
wisp of convenience might be one of them, but thwarting a cache system  
is not.  
If the problem’s in the View, fix it in the View!

–  
Phlip
