预编译文件不起作用
Precomopiling files doesnt work fine
我正在用leaflet.js开发项目。我有一个javascript文件,它必须更新公司的坐标。因此,当我在开发ENV时,rails使用map_update.coffee.erb,一切都很顺利。一旦我尝试制作rake资产:预编译并在生产ENV中启动本地服务器,映射就会被破坏。它正在工作,但与开发ENV完全不同。
我的js文件是预编译的(我可以在public/assets/map中看到它),因为我在production.rb中显式地预编译了它。
任何想法都会很棒!如果你需要我的一些文件,只要问我,我会提供我写的所需代码。谢谢
编辑production.rb:
Application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
require 'syslog/logger'
config.logger = Syslog::Logger.new 'abw'
config.logger.level = 2
config.assets.precompile += %w( application-ie.css application-ie.js )
config.assets.precompile += %w( abwp.css.scss abwp.css xgemius.js )
config.assets.precompile += %w( map/map.js map/map_update.js )
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
map_update.coffee.erb,它在dev-env中工作,预编译后不在生产中:
#= require map/map.coffee.erb
jQuery $ ->
coord = $('#coordinates-val').val().replace('[',"").replace(']',"").split(",").map(Number)
loc = [coord[1], coord[0]]
map.setCompanyLocation loc
map.layers.companyLocationMarker.on 'dragend', (e) ->
$('#coordinates-val').val(e.target._latlng.lng + ", " + e.target._latlng.lat)
$("#location-detector-update").on 'click', (e) ->
e.preventDefault()
address = $("#location-address").val()
errorElement = $("#location-error")
if address.length > 0
$.ajax
url: 'http://geocode-maps.yandex.ru/1.x/'
type: 'get'
data:
geocode: address
format: 'json'
results: 1
,success: (data) =>
if typeof(data) == 'string'
data = JSON.parse(data)
if data.response.GeoObjectCollection.featureMember.length > 0
_location = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos.split(" ")
_location[0] = 0 if _location[0] == null
_location[1] = 0 if _location[1] == null
location = new L.LatLng(_location[1], _location[0])
map.setCompanyLocation location
$('#coordinates-val').val(_location[0] + ", " + _location[1])
map.layers.companyLocationMarker.on 'dragend', (e) ->
$('#coordinates-val').val(e.target._latlng.lng + ", " + e.target._latlng.lat)
errorElement.html ""
else
errorElement.html "Не найдено"
"不工作"意味着,当我在运行dev-env的同时更新坐标时,一切都如我所期望的那样工作:如果公司有坐标,它会显示它们,并提供输入地址的机会,并向数据库发布另一个坐标。若公司并没有坐标,地图将在自定义的默认位置初始化。在生产环境中,我只看到标记,没有地图图片。仍然可以输入地址查找坐标并将其发布到数据库,但我看不到地图本身,因此无法将标记移动到正确的位置。啊,忘了。Cath the view:
#map
.map-filter
#location-error
.input-append.adress-input
= text_field_tag 'location-address', nil, class: 'input', placeholder: 'Enter your adress'
= link_to nil, class: 'btn', id: 'location-detector-update' do
i.icon-search
= javascript_include_tag 'map/map_update'
= render 'form_coordinates'
希望这已经足够开始了。
还有一件事。我有另一种观点,只是想看看公司的地图,我可以做到。因此映射正在正确初始化。正如我所悲伤的,我的map_update.coffee.erb 预编译中的问题
所以,我终于找到了问题。
我在update_map.js map.js中要求,它有自己的window.map实例化。它不适合这种更改标记的情况。我重写了update_map.js,现在它使用了它自己的window.map实例
ACTIVEOBJECTICON = L.icon
iconUrl: '<%= image_path("green-marker.png") %>',
iconSize: [25, 41],
iconAnchor: [13, 41]
draggable: true
class EditMap extends L.Map
constructor: (id, params) ->
super id, params
@layers =
companyLocationMarker: new L.LayerGroup()
activeObjectMarker: new L.LayerGroup()
@activeObjectIcon = ACTIVEOBJECTICON
@putInit()
putInit: =>
if coord == "[0]" || coord == ""
alert("You didn't setup adress.")
else
latLng = coord.replace('[',"").replace(']',"").split(",").map(Number)
val1 = latLng[1]
val0 = latLng[0]
location = new L.LatLng(val1, val0)
@layers.activeObjectMarker = new L.Marker(location, { icon: @activeObjectIcon} )
@addLayer(@layers.activeObjectMarker)
@layers.activeObjectMarker.dragging.enable()
@setView(location, 15)
@panTo location
setCompanyLocation: (location) =>
@currentLocation = location
map.renderCompanyLocation()
renderCompanyLocation: =>
locationIcon = ACTIVEOBJECTICON
@removeLayer(@layers.activeObjectMarker)
@removeLayer(@layers.companyLocationMarker)
@layers.companyLocationMarker = new L.Marker(@currentLocation, { icon: locationIcon })
@addLayer(@layers.companyLocationMarker)
@layers.companyLocationMarker.dragging.enable()
@setView(@currentLocation, 15)
jQuery $ ->
osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
osmTiles = new L.TileLayer osmUrl,
maxZoom: 18
window.map = new EditMap 'map',
attributionControl: false,
zoom: 12,
doubleClickZoom: false
center: new L.LatLng(53.9060, 27.5549)
map.addLayer osmTiles
$("#location-detector-update").on 'click', (e) ->
e.preventDefault()
address = $("#location-address").val()
errorElement = $("#location-error")
if address.length > 0
$.ajax
url: 'http://geocode-maps.yandex.ru/1.x/'
type: 'get'
data:
geocode: address
format: 'json'
results: 1
,success: (data) =>
if typeof(data) == 'string'
data = JSON.parse(data)
if data.response.GeoObjectCollection.featureMember.length > 0
_location = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos.split(" ")
_location[0] = 0 if _location[0] == null
_location[1] = 0 if _location[1] == null
location = new L.LatLng(_location[1], _location[0])
map.setCompanyLocation location
$('#coordinates-val').val(_location[0] + ", " + _location[1])
map.layers.companyLocationMarker.on 'dragend', (e) ->
$('#coordinates-val').val(e.target._latlng.lng + ", " + e.target._latlng.lat)
errorElement.html ""
else
errorElement.html "Unable to find"
production.rb也是如此。
- 带有凭据的角度文件上载(CORS)不起作用
- html文件中的script标记根本不起作用
- grunt上的压缩文件夹不起作用
- 当我在浏览器中打开HTML文件时,javascript不起作用
- AJAX上传文件不起作用
- 在Hapi.js中提供静态JavaScript文件不起作用
- ngResource没有'从JSON文件解析HTML时不起作用
- jQueryAjax调用在单独的.js文件中不起作用
- PhoneGap读写文件获胜'不起作用
- 我尝试使用我的本地js文件来获取远程IP数据,但它不起作用
- 某些js文件在Drupal中不起作用
- 使用gulp-angular gettext从JS文件中提取字符串不起作用
- google.setOnLoadCallback()在单独的JS文件中不起作用
- css&js文件在php中不起作用
- 从HTML链接时,Javascript文件不起作用
- 如果在include文件中使用连接,Jquery ajax调用将不起作用
- php文件中包含的jquery文件在服务器上不起作用
- Cufon-builder-font-js文件在Fabric.js中不起作用
- 如果.htaccess文件中只写了一行代码,那么我所有的css和js都不起作用,如何修复它
- Haskell调用Node.js文件不起作用