问题描述
||
我在我的erb文件之一中使用以下行:
<%=@map.div(:width => 800,:height => 500)%>
它输出以下HTML:
<div id=\"map\" style=\"width:800px;height:500px\" ></div>
显示为:<div id=\"map\" style=\"width:800px;height:500px\" ></div>
在浏览器中。
编辑:我唯一的另一段代码是:
require \'rubygems\'
include GeoKit::Geocoders
class HomeController < ApplicationController
def index
coordinates =[13.0343841,80.2502535] #you can get the coordinates for the location you want from http://stevemorse.org/jcal/latlon.php
@map = GMap.new(\'map\')
@map.control_init(:large_map => true,:map_type => true)
@map.center_zoom_init(coordinates,10) # here 10 referes to the zoom level for a map
@map.overlay_init(GMarker.new(coordinates,:title => \'Chennai\',:info_window => \'Chennai\'))
end
end
为什么这样做呢?如何防止Rails 3将我的代码转换为特殊字符?
解决方法
据我们对
div
方法一无所知,您可以尝试一下
<%= @map.div(:width => 800,:height => 500).html_safe %>
最好以div
方法将html_safe
添加到输出中