Emily huang Emily huang - 1 year ago 98
CoffeeScript Question

ExecJS::RuntimeError in ChatRooms#show

The issue I'm having:

enter image description here

This is my room.coffee file, and everything works well.

jQuery(document).on 'turbolinks:load', ->
messages = $('#messages')
if $('#messages').length > 0

App.global_chat = App.cable.subscriptions.create {
channel: "ChatRoomsChannel"
chat_room_id: messages.data('chat-room-id')
connected: ->
# Called when the subscription is ready for use on the server

disconnected: ->
# Called when the subscription has been terminated by the server

received: (data) ->
# Data received

send_message: (message, chat_room_id) ->
@perform 'send_message', message: message, chat_room_id: chat_room_id

@import "bootstrap-sprockets";
@import "bootstrap";

#messages {
max-height: 450px;
overflow-y: auto;
.avatar {
margin: 0.5rem;

<h1><%= @chat_room.title %></h1>

<div id="messages" data-chat-room-id="<%= @chat_room.id %>">
<%= render @chat_room.messages %>


<%= form_for @message, url: '#' do |f| %>
<%= hidden_field_tag 'chat_room_id', @chat_room.id %>
<div class="form-group">
<%= f.label :body %>
<%= f.text_area :body, class: 'form-control' %>
<small class="text-muted">From 2 to 1000 characters</small>

<%= f.submit "Post", class: 'btn btn-primary btn-lg' %>
<% end %>

But it shows ExecJS::RuntimeError after I added the code down below in the same file.

$('#new_message').submit (e) ->
$this = $(this)
textarea = $this.find('#message_body')
if $.trim(textarea.val()).length > 1
App.global_chat.send_message textarea.val(), messages.data('chat-room-id')
return false

I did search similar problems a lot, and most people who use pc encountered this issue. But I'm using mac, I have no idea why I got this error as well.

Answer Source

You need javascript runtime environment

Install node.js or add therubyracer gem

sudo apt-get install nodejs

OR Add therubyracer gem in your Gemfile

gem 'therubyracer'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download