1

ExecJS::RuntimeError当我尝试启动 Rails 服务器并且服务器日志给我以下信息时,我得到了:

   ActionView::Template::Error (delete operand may not be argument or var
      (in /home/sergey/Perfecto/arena/app/assets/javascripts/items.js.coffee)):
        47:         <%= raw flash_messages %>
        48:     </div>
        49: 
        50:     <%= javascript_include_tag "application" %>
        51:     <%= yield :javascripts %>
        52:     <%= yield :scripts %>
        53: </body>

我发现发生此错误是因为 Ubuntu 没有安装 javascript 运行时。好的。我已经nodejs v0.6.3从源安装并尝试按照建议添加gem 'therubyracer'到我Gemfile的,但错误仍然出现。

我错过了什么?提前致谢。

我的items.js.coffee样子是这样的:

jQuery ->
    if $('#main.items_controller.new').length > 0   
        overlay = null
        iconOffsetX = 26
        iconOffsetY = 52 

        disableDraggingFor = (el) ->
            el.draggable = false
            el.onmousedown = (event) ->
                event.preventDefault()
                return false

        $(".draggable_item, #new_items_queue").disableSelection()

        $.each $(".draggable_item"), (i, el) ->
      disableDraggingFor(el)

        showInfobox = (marker,data) ->
            boxText = document.createElement("div")
            boxText.style.cssText = "height: 100%; background: url('/images/form.png') no-repeat;"
            boxText.innerHTML = '<div id="infoboxContent">' + data + '</div>'

            myOptions =
                content: boxText
                disableAutoPan: false
                maxWidth: 0
                pixelOffset: new google.maps.Size(-79, -386)
                zIndex: 0
                boxStyle:
                    width: "650px"
                    height: "350px"
                closeBoxMargin: "10px"
                infoBoxClearance: new google.maps.Size(1, 1)
                isHidden: false
                pane: "floatPane"
                enableEventPropagation: false

            ib = new InfoBox(myOptions)
            oldDraw = ib.draw
            ib.draw = ->
                oldDraw.apply(@)
                jQuery(ib.div_).hide()
                jQuery(ib.div_).fadeIn(900)

                $("#item_name").focus()

                priceResult = $("#converted_price")
                $("#item_price").live "keydown keyup keypress focus blur paste change", ->
                    fx.base = "USD"
                    fx.rates = 
                        "KGS": 46.4
                    input = accounting.unformat $("#item_price").val()
                    result = accounting.formatMoney fx.convert(input, from: "USD", to: "KGS"), 
                        symbol: "сом"
                        precision: 0
                        thousand: " "
                        format: 
                            pos : "%v %s"
                            neg : "(%v) %s"
                            zero: "0 %s"
                    priceResult.html result

            ib.open(Gmaps.map.map, marker)

            google.maps.event.addListener marker, 'dragstart', ->
                ib.hide()

            google.maps.event.addListener marker, 'dragend', ->
                newPosition = @getPosition()
                $.ajax "/items/reverse_geocode",
                    type: 'GET'
                    dataType: 'text'
                    data: 
                        lat: newPosition.lat()
                        lng: newPosition.lng()
                    error: (jqXHR, textStatus, errorThrown) ->
                    console.log "AJAX Error: #{textStatus}"
                    success: (data, textStatus, jqXHR) ->
                        $("#item_location").val data
                        ib.show()
                $('#item_latitude').val newPosition.lat()
                $('#item_longitude').val newPosition.lng()

            google.maps.event.addListener ib, 'domready', ->
                $('#change_position').bind 'click', ->
                    ib.close()
                    marker.setAnimation google.maps.Animation.BOUNCE

                    google.maps.event.addListener marker, 'position_changed', ->
                        setTimeout (->
                                                    ib.open(Gmaps.map.map, marker)
                                                ), 300

            google.maps.event.addListener ib, 'closeclick', -> 
                marker.setMap(null)
                delete marker
                $(".draggable_item").draggable("enable")

        placeMarker = (location,icon,shadow,kind) ->
            $.ajax "/items/reverse_geocode",
                type: 'GET'
                dataType: 'text'
                data: 
                    lat: location.lat()
                    lng: location.lng()
                    onlyCountry: true
                error: (jqXHR, textStatus, errorThrown) ->
                console.log "AJAX Error: #{textStatus}"
                success: (data, textStatus, jqXHR) ->
                    if data != "Киргизия"
                        humane "Вы можете добавлять объявления только в Кыргызстане"
                    else
                        $(".draggable_item").draggable("disable")

                        marker = new google.maps.Marker
                           position: location
                           map: Gmaps.map.map
                           icon: icon
                           shadow: shadow
                           draggable: true
                           zIndex: 99

                        $.ajax "/items/new.js",
                            type: 'GET'
                            dataType: 'text'
                            data: 
                                content: kind
                                lat: location.lat()
                                lng: location.lng()
                            error: (jqXHR, textStatus, errorThrown) ->
                            console.log "AJAX Error: #{textStatus}"
                            success: (data, textStatus, jqXHR) ->
                                 showInfobox marker, data

        Gmaps.map.callback = ->
            @.map.mapTypes.set "OSM", new google.maps.ImageMapType(
              getTileUrl: (coord, zoom) ->
                "http://192.168.0.112/osm_tiles2/" + zoom + "/" + coord.x + "/" + coord.y + ".png"

              tileSize: new google.maps.Size(256, 256)
              name: "OpenStreetMap"
              maxZoom: 18
            )
            @.map.setMapTypeId("OSM")
            overlay = new google.maps.OverlayView()
            overlay.draw = ->
            overlay.setMap @.map

        $.each $(".draggable_item"), ->
            $(@).draggable 
                cursor: "move",
                revert: false,
                helper: 'clone',
                stop: (event,ui) ->
                    point = new google.maps.Point ui.offset.left+iconOffsetX,ui.offset.top+iconOffsetY
                    location = overlay.getProjection().fromContainerPixelToLatLng(point)
                    placeMarker location, $(@).data('marker'), $(@).data('shadow'), $(@).data('kind')
4

3 回答 3

4

你的 CoffeeScript 中有这个:

google.maps.event.addListener ib, 'closeclick', -> 
    marker.setMap(null)
    delete marker
    $(".draggable_item").draggable("enable")

错误是这样说的:

删除操作数不能是参数或 var

如果您从 that 回溯 CoffeeScript delete marker,您会看到这marker是一个参数,并且您不能delete在参数上使用 JavaScript 运算符。

delete marker你应该能够在不引起问题的情况下摆脱它,只是marker.setMap(null)应该足以让它消失。

于 2012-04-25T04:23:39.193 回答
0

尝试在您的 Gemfile 中添加 gem "execjs", "~> 1.3.0"。我想它可以解决这个问题......

于 2012-04-25T04:02:15.513 回答
0

较旧的线程,但我也有同样的问题,但通过简单地重命名我的 javascript 并删除所有文件名末尾的“.coffee”来解决它。

例如:

从:

'name'.js.coffee

至:

'name'.js

出于某种原因,这行得通。

于 2013-05-19T18:44:00.537 回答