Sergey K
Sergey K

Reputation: 5107

Rails 3.2.3 ExecJS::RuntimeError

I'm getting ExecJS::RuntimeError when i try to start Rails server and the server log gives me the following:

   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>

I found that this error happens because Ubuntu don't have a javascript runtime installed. Okay. I've installed nodejs v0.6.3 from sources and tried to add gem 'therubyracer' to my Gemfile as it was suggested but the error still apperars.

What have i missed? Thanks in advance.

My items.js.coffee looks like this:

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')

Upvotes: 1

Views: 2504

Answers (3)

sp89
sp89

Reputation: 418

Older thread but I had the same issue as well but solved it by simply renaming my javascript and deleting the '.coffee' at the end of all the file names.

For example:

From:

'name'.js.coffee

to:

'name'.js

For some reason or another this worked.

Upvotes: 0

mu is too short
mu is too short

Reputation: 434985

You have this in your CoffeeScript:

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

And the error say this:

delete operand may not be argument or var

If you backtrack through your CoffeeScript from that delete marker, you'll see that marker is an argument and you can't use the JavaScript delete operator on an argument.

You should be able to get rid of that delete marker without causing problems, just the marker.setMap(null) should be enough to make it go away.

Upvotes: 4

Victor Rodrigues
Victor Rodrigues

Reputation: 149

Try to add gem "execjs", "~> 1.3.0" at your Gemfile. I guess it can fix this...

Upvotes: 0

Related Questions