# Moving HTML out of a model

**URL:** <https://www.ruby-forum.com/t/moving-html-out-of-a-model/147772>\
**Category:** Rails\
**Created:** [September 5, 2008, 9:01am UTC](https://www.ruby-forum.com/t/moving-html-out-of-a-model/147772 "2008-09-05T09:01:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [September 5, 2008, 9:01am UTC](https://www.ruby-forum.com/t/moving-html-out-of-a-model/147772/1 "2008-09-05T09:01:18Z")

</div>

G’day folks. My RentalMap model uses ym4r\_gm to generate a Google map  
and plot markers on the map. However, a marker’s body contains HTML.  
It feels dirty to put HTML in the model, but the markers should be  
plotted by the model. Any suggestions for how I can move the marker  
HTML template out of the RentalMap model?

Cheers,  
Nick

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [September 5, 2008, 11:05am UTC](https://www.ruby-forum.com/t/moving-html-out-of-a-model/147772/2 "2008-09-05T11:05:39Z")

</div>

Hi Nick,

> G’day folks. My RentalMap model uses ym4r\_gm to generate a Google map  
> and plot markers on the map. However, a marker’s body contains HTML.  
> It feels dirty to put HTML in the model, but the markers should be  
> plotted by the model. Any suggestions for how I can move the marker  
> HTML template out of the RentalMap model?

I think something like the acts\_as\_renderer plugin maybe what you need:

[http://rubyforge.org/projects/actsasrenderer/](http://rubyforge.org/projects/actsasrenderer/)

It allows you to render view output from inside a model - “Now you can  
violate MVC the easy way!”

Regards,

Tony.

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [September 5, 2008, 2:32pm UTC](https://www.ruby-forum.com/t/moving-html-out-of-a-model/147772/3 "2008-09-05T14:32:54Z")

</div>

Also… there’s some validity to the argument that a model’s domain  
might very well be creating markup and in such cases, HTML generation  
in the model could be quite justified. YMMV and HTH. 🙂

RSL

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [September 5, 2008, 6:23pm UTC](https://www.ruby-forum.com/t/moving-html-out-of-a-model/147772/4 "2008-09-05T18:23:21Z")

</div>

On 2008-09-05, at 05:05, Tony Byrne wrote:

> [http://rubyforge.org/projects/actsasrenderer/](http://rubyforge.org/projects/actsasrenderer/)
> 
> It allows you to render view output from inside a model - “Now you  
> can violate MVC the easy way!”
> 
> Regards,
> 
> Tony.

Thanks for the tip, Tony. I hadn’t heard about actsasrenderer. I’ll  
give it a try and see how it feels.
