2017-01-10 9 views
1

私は、ユーザーが特定のタスクにコメントを付けることができるレールアプリを持っています。そして、タスクにコメントが投稿されるたびに、そのプロジェクトに従うユーザーは通知を受けるべきです。通知が私のレールアプリに読み込まれていない

(私の通知アイコンが保持されている)部分_navigation_links.html.erb

class Notifications 
    constructor: -> 
     @notifications = $("[data-behavior='notifications']") 
     @setup() if @notifications.length >0 

    setup: -> 
     $.ajax(
      url: "/notifications.json" 
      dataType: "JSON" 
      method: "GET" 
      success: @handleSuccess 
     ) 

    handleSuccess: (data) => 
     items = $.map data, (notification) -> 
      "<a class='dropdown-item' href="#">#{notification.actor} #{notification.action} #{nofication.notifiable.type}</a>" 
     $("[data-behavior='notification-items']").html(items) 

jQuery -> 
    new Notifications 

notifications.js.coffee

<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse"> 
    <span class="glyphicon glyphicon-user white"></span> 
</button> 
<div class="collapse navbar-collapse navHeaderCollapse"> 
    <ul class="nav navbar-nav"> 

     <li><%= link_to "start a project", new_project_path %></li> 

     <% if user_signed_in? %> 

     <li class="nav-item btn-group" data-behavior="notifications"> 
      <a class="dropdown-toggle nav-link" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="fa"> 
       <%= fa_icon "bell" %> 
      </a> 
      <div class="dropdown-menu" aria-labelledby="dropdownMenu1" data-behavior="notification-items"> 

      </div> 
     </li> 

     <div class="dropdown" style="float: right; margin-left: 20px; margin-top: 15px;"> 
      <li class="dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" style="cursor: pointer;"> 
      <%= current_user.username %> 
      <span class="caret"></span> 
      </li> 
      <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> 
       <li><%= link_to 'My Profile', users_following_user_path(current_user) %></li> 
      <li><%= link_to 'Edit Profile', profile_user_path(current_user) %></li> 
       <li><%= link_to 'Account Settings', edit_user_path(current_user) %></li> 
      <li role="separator" class="divider"></li> 
       <li><%= link_to 'Log out', destroy_user_session_path, method: :delete %></li> 
      </ul> 
     </div> 
     <% elsif %> 
      <li><%= link_to "Sign Up", new_user_registration_path %></li> 
      <li><%= link_to "Sign In", new_user_session_path %></li> 
     <% end %> 

    </ul> 
</div> 
:私は、通知のアイコンをクリックすると、私のAJAX通知がポップアップ表示されませんモデルnotification.rb

routes.rbを

resources :notifications 

私が行ってきたカップルのチュートリアルから、ナビゲーションリンクのベルアイコンをクリックすると通知がポップアップするはずです。しかし、javascriptは動作していません...

何か助けていただければ幸いです。

+0

コンソールにエラーがありますか? – max

答えて

1

notifications.js.coffeeファイルにタイプミスがあり、以下の(変化href='#'href="#")にhandleSuccess機能を変更してください:

handleSuccess: (data) => 
    items = $.map data, (notification) -> 
     "<a class='dropdown-item' href='#'>#{notification.actor} #{notification.action} #{nofication.notifiable.type}</a>" 
    $("[data-behavior='notification-items']").html(items) 

これは、問題を修正する必要があります。

関連する問題