Precomopiling文件无法正常工作(Precomopiling files doesnt work fine)

编程入门 行业动态 更新时间:2024-10-18 10:14:15
Precomopiling文件无法正常工作(Precomopiling files doesnt work fine)

我正在用leaflet.js开发项目。 我有javascript文件,必须更新公司的坐标。 因此,当我在开发ENV时,rails使用map_update.coffee.erb,一切运行顺利。 一旦我尝试制作rake资产:预编译并在生产环境中启动我的本地服务器,地图就会被破坏。 它有效,但与开发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观点:

#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预编译出了问题

I'm developing project with leaflet.js thing. I have javascript file that has to update coordinates of the company. So while I'm in development ENV, and rails use map_update.coffee.erb, everything is working smoothly. As soon as I'm trying to make rake assets:precompile and to start my local server in production ENV, map becomes broken. It's working, but absolutely different from development ENV.

My js file is precompiled(I can see it in public/assets/map), because I explicitly precompile it in production.rb. But it doesn't work good.

Any ideas would be great! And if you need some of my files, just ask me, I'll provide needed code, that I've wrote. Thanks!

edit 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 that is working in dev env and doesn't in production after precompilation:

#= 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 "Не найдено"

"Doesn't work" means, when I'm on the page of updating coordinates while running dev env, everything is work as I expect: if company has coordinates, it show them and give the apportunity to enter adress and posts another coorinates to the db. If company doesn't have coordinates, map is initializing in customized default place. In production env I see only marker and no map picture. Still can enter the adress find coordinates and post it to db, but I don't see the map itself and because of that can't move the marker to the right place. Ah, forgot. 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'

Hope that's enough for start.

And one more thing. I have another view just to see the map of the company and I can do that. So the map is initializing properly. As I sad, problems in precompilation of my map_update.coffee.erb

最满意答案

所以,最后,我发现了问题。

我在update_map.js中要求map.js,它有自己的window.map实例化。 它不适合这种改变标记的情况。 我重写了我的update_map.js,现在它正在使用它自己的window.map实例。 这是我的update_map.js:

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是一样的。

So, finally, I found the problem.

I was requiring in my update_map.js map.js, wich has it's own instantiating of window.map. It was not suitable for this case of changing the marker. I rewrote my update_map.js and now it's using its' own instance of window.map. This is my update_map.js:

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 is the same.

更多推荐

map,config,production,assets,电脑培训,计算机培训,IT培训"/> <meta name="

本文发布于:2023-07-14 18:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106667.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   文件   工作   Precomopiling   fine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!