# Where to put mapping functionality

**URL:** <https://www.ruby-forum.com/t/where-to-put-mapping-functionality/147687>\
**Category:** Rails\
**Created:** [September 4, 2008, 9:28am UTC](https://www.ruby-forum.com/t/where-to-put-mapping-functionality/147687 "2008-09-04T09:28:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [September 4, 2008, 9:28am UTC](https://www.ruby-forum.com/t/where-to-put-mapping-functionality/147687/1 "2008-09-04T09:28:07Z")

</div>

Hey guys. I’ve been trying to figure out where in my app this  
functionality should go, but I’m really not sure. Any suggestions?

1. A map can be created for a Neighbourhood or Property.
2. A map has zero or more markers.
3. A marker contains HTML formatted from a template, using a  
Property’s attributes.

#1 means that the map functionality should be separate from  
Neighbourhoods and Properties, otherwise it won’t be DRY. IMO, this  
suggests that I should create a map model, or put the mapping  
functionality in a module in lib/ .

#3 is related to views. The marker HTML template could go in a:  
-view helper. However, only views have access to view helpers, so the  
helper would only be accessible from the view. This would require  
putting business logic into the view. Ew.  
-partial. The Neighbourhood and Property controllers could then use  
#render\_to\_string to generate each marker’s contents. I don’t believe  
it’s possible [without an ugly kludge, at least] to get a model to  
call #render\_to\_string .

My current line of thinking is:  
-Create a ‘map’ model.  
-Put the map marker HTML template in a partial.  
-The Neighbourhood and Property controllers create a map instance.  
-The Neighbourhood and Property controllers add map markers.  
-Addng map markers calls #render\_to\_string to generate a marker’s  
contents.

However, I feel like the Neighbourhood and Property models should be  
creating the map instance and adding markers.

Any suggestions? I’m all ears!  
-Nick
