我正在关注来自here行的确切代码。我有大多数工作,但当我加载users / index.html.erb时,我在控制台中收到错误:
Uncaught ReferenceError: require is not defined
它是Rails 3 vs Rails 4问题吗?
我不明白,因为我的application.js文件与他们的文件完全相同...
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap.min
//= require private_pub
//= require chat
//= require turbolinks
//= require_tree .
从Chrome检查器我可以看到...
我有一个GIT回购here。
我的private_pub.yml文件看起来像这样......
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "http://example.com/faye"
secret_token: "58799f71c1c0c50377b86e4aebec075f5065264d8570349367054464c5f77890"
signature_expiration: 3600 # one hour
我的private_pub.ru文件看起来像这样......
# Run with: rackup private_pub.ru -s thin -E production
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"
Faye::WebSocket.load_adapter('thin')
PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app
解决方案here建议将其添加到conversation / show.html.erb文件...
<% content_for :bottom do %>
<%= subscribe_to "/mesajlar/new" %>
<% end %>
我的user / index.html.erb文件看起来像这样......
<div class="row">
<!-- Not implemented on tutorial -->
<div class="col-md-4">
<div style="height: 300px; overflow-y: auto;">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">Registered Users</div>
<!-- Table -->
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<% @users.each_with_index do |user, index| %>
<tr>
<td><%= index +=1 %></td>
<td><%= user.email %></td>
<td>
<%= link_to "Send Message", "#", class: "btn btn-success btn-xs start-conversation",
"data-sid" => current_user.id, "data-rip" => user.id %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<hr>
<h3>Your Conversations</h3>
<div style="height: 400px; overflow-y: auto;">
<% if @conversations.any? %>
<ul class="media-list">
<% @conversations.each do |conversation| %>
<li class="media">
<%= image_tag("http://placehold.it/50x50", class: "media-object pull-left") %>
<div class="media-body">
<%= link_to "", conversation_path(conversation), class: "conversation", "data-cid" => conversation.id %>
<h4 class="media-heading"><%= conversation_interlocutor(conversation).email %></h4>
<p><%= conversation.messages.last.nil? ? "No messages" : truncate(conversation.messages.last.body, length: 45) %></p>
</div>
</li>
<% end %>
</ul>
<% else %>
<p>You have no conversations. Click send message with any user to create one.</p>
<% end %>
</div>
</div>
<div class="col-md-4">
</div>
</div>
session / show.html.erb看起来像这样......
<div class="chatboxhead">
<div class="chatboxtitle">
<i class="fa fa-comments"></i>
<h1><%= @reciever.name %> </h1>
</div>
<div class="chatboxoptions">
<%= link_to "<i class='fa fa-minus'></i> ".html_safe, "#", class: "toggleChatBox", "data-cid" => @conversation.id %>
<%= link_to "<i class='fa fa-times'></i> ".html_safe, "#", class: "closeChat", "data-cid" => @conversation.id %>
</div>
</div>
<div class="chatboxcontent">
<%debugger%>
<% if @messages.any? %>
<%= render @messages %>
<% end %>
</div>
<div class="chatboxinput">
<%= form_for([@conversation, @message], :remote => true, :html => { id: "conversation_form_#{@conversation.id}"}) do |f| %>
<%= f.text_area :body, class: "chatboxtextarea", "data-cid" => @conversation.id %>
<% end %>
</div>
<% content_for :bottom do %>
<%= subscribe_to conversation_path(@conversation) %>
<% end %>
更新
我已将所有引导程序文件添加到assets / javascript