# Problem with RJS

**URL:** <https://www.ruby-forum.com/t/problem-with-rjs/172943>\
**Category:** Rails\
**Created:** [July 30, 2009, 11:26am UTC](https://www.ruby-forum.com/t/problem-with-rjs/172943 "2009-07-30T11:26:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shakor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@shakor](https://www.ruby-forum.com/u/shakor)\
**Post date:** [July 30, 2009, 11:26am UTC](https://www.ruby-forum.com/t/problem-with-rjs/172943/1 "2009-07-30T11:26:35Z")

</div>

Hi,

I am trying to do a rails application that uses google map to allow  
users to specify longitude and latitude and then the google map should  
be updated to show that location which was specified.

I am using observe\_field on the text field like this:

```
    <%= observe_field 'geo_loc_cords',
    :url => {:action => :update_map, :form_authenticity_token =>

```

form\_authenticity\_token},  
:update =\> :map,  
:with =\> ‘“cords=”+element.value’,  
:loading =\> “Element.show(‘spinner’)”,  
:complete =\> “Element.hide(‘spinner’)” %\>

and my map div looks like this:

\<%= @map.div(:width =\> 400, :height =\> 300) %\>

and in the update\_map action I have this (hardcoded the coordinates for  
now):

def update\_map()  
latitude = 43.023849  
longitude = -77.682053  
@map = Variable.new(“map”)

```
point = GLatLng.new([latitude, longitude])
@marker = GMarker.new(point, {:title => "Site:", :info_window =>

```

“Site:”,  
:draggable =\> true})  
respond\_to do |format|  
format.html  
format.js  
end  
end

And my rjs template simply looks like this:

page \<\< @map.clear\_overlays  
page \<\< @map.add\_overlay(@marker)

Yet the result is simply outputted on the page as:

try { map.clearOverlays(); map.addOverlay(addInfoWindowToMarker(new  
GMarker(new GLatLng(43.023849,-77.682053),{title : “Site:”,draggable :  
true}),“Site:”,{})); } catch (e) { alert(‘RJS error:\n\n’ +  
e.toString());  
alert(‘map.clearOverlays();\nmap.addOverlay(addInfoWindowToMarker(new  
GMarker(new GLatLng(43.023849,-77.682053),{title : “Site:”,draggable :  
true}),“Site:”,{}));’); throw e }

What am I doing wrong to make the resulting javascript outputted on the  
page rather than interpreted as javascript?

---

<div class="post-metadata">

**Author:** ![shakor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@shakor](https://www.ruby-forum.com/u/shakor)\
**Post date:** [July 30, 2009, 12:40pm UTC](https://www.ruby-forum.com/t/problem-with-rjs/172943/2 "2009-07-30T12:40:36Z")

</div>

Shahin K. wrote:

> Hi,
> 
> I am trying to do a rails application that uses google map to allow  
> users to specify longitude and latitude and then the google map should  
> be updated to show that location which was specified.
> 
> I am using observe\_field on the text field like this:
> 
> ```
> <%= observe_field 'geo_loc_cords',
> :url => {:action => :update_map, :form_authenticity_token =>
> 
> ```
> 
> form\_authenticity\_token},  
> :update =\> :map,  
> :with =\> ‘“cords=”+element.value’,  
> :loading =\> “Element.show(‘spinner’)”,  
> :complete =\> “Element.hide(‘spinner’)” %\>
> 
> and my map div looks like this:
> 
> \<%= @map.div(:width =\> 400, :height =\> 300) %\>

.  
.  
.

> What am I doing wrong to make the resulting javascript outputted on the  
> page rather than interpreted as javascript?

Solved it, just needed to remove the :update =\> :map in observe field.  
🙂
