2016-10-02 4 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

あなたが

node.jsをインストールするか、therubyracer宝石を追加

sudo apt-get install nodejs 

OR ファイルをごroom.coffeeであなたのGemfile

gem 'therubyracer' 
0

therubyracer宝石を追加するJavaScriptランタイム環境を必要とするあなたのc odeは2つのスペースを使用してインデントされます。コードでは、字下げを追加したことはそれ以上です。 $('#new_message').submit (e) ->の後に2つのスペースインデントに一致するセクションを上書きすると、構文エラーが解決されます。

関連する問題