0

I am following the exact code from here line for line. I have most things working, but when I load users/index.html.erb I get the error in the console:

Uncaught ReferenceError: require is not defined

Is it a Rails 3 vs Rails 4 issue?

I don't understand though because my application.js file is the exact same as their's...

// 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 .

From the Chrome inspector I can see this...

enter image description here

I have a GIT repo here.

My private_pub.yml file looks like this...

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

My private_pub.ru file looks like this...

# 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

Solution here recommended adding this to the conversation/show.html.erb file...

<% content_for :bottom do %>
<%= subscribe_to "/mesajlar/new" %>
<% end  %>

My user/index.html.erb file looks like this...

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

And conversation/show.html.erb looks like this...

<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 %>
    &nbsp;&nbsp;
    <%= 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 %>

UPDATE

I have added all the bootstrap files to assets/javascript

enter image description here

Community
  • 1
  • 1
Kendall Weihe
  • 2,021
  • 4
  • 27
  • 53

0 Answers0