显示带有特殊字符代码的html,只需将其用作html即可

问题描述

|| 我在我的erb文件之一中使用以下行:
<%=@map.div(:width => 800,:height => 500)%>
它输出以下HTML:
&lt;div id=\"map\" style=\"width:800px;height:500px\" &gt;&lt;/div&gt;
显示为:
<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
添加到输出中     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...