2016-10-02 57 views
0

我遇到的问题:ExecJS :: RuntimeError在聊天室#显示

enter image description here

这是我room.coffee文件,一切正常。

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 %> 
 
</div> 
 

 
<hr> 
 

 
<%= 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> 
 
    </div> 
 

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

但它显示ExecJS :: RuntimeError后,我在同一个文件添加的代码下面下来。

$('#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') 
 
     textarea.val('') 
 
     e.preventDefault() 
 
     return false

我做搜索类似的问题很多,谁使用PC大多数人遇到过这个问题。但我正在使用mac,我不知道为什么我也有这个错误。

+0

http://stackoverflow.com/questions/8362458/error-when-running-rails-app-execjsruntimeerror – JGutierrezC

回答

1

需要Javascript运行环境

安装node.js或添加therubyracer宝石

sudo apt-get install nodejs 

ORGemfile

gem 'therubyracer' 
0

添加therubyracer宝石在你room.coffee提交您C ode使用两个空格缩进。在你添加缩进的代码中不止这些。如果您在$('#new_message').submit (e) ->之后超出部分以匹配两个空格缩进,则将解析语法错误。