我正在尝试将通知包含在我的Rails应用程序中,并且我正在按照本教程中的字母操作:https://gorails.com/episodes/in-app-navbar-notifications
一切正常,直到我想将通知动态附加到html为止。
coffescript文件似乎根本没有执行。即使我只想console.log div也不执行
navbar.html.erb
<% if current_user.is_a?(User) %>
<div class="icon">
<div class="btn-group dropleft" data-behavior="notifications">
<a class="dropdown-toggle" data-toggle="dropdown" aria-
haspopup="true" aria-expanded="false" href="#" data-
behavior="notifications-link">
<i class="far fa-bell icon-selector"></i><span data-
behavior="unread-count"></span>
<p>Notifications</p>
</a>
<div class="dropdown-menu" data-behavior="notification-items">
<a href="#" class="dropdown-item">Action</a>
</div>
</div>
</div>
....
notifications.js.coffee
class Notifications
constructor: ->
@notifications = $("[data-behavior='notifications']")
@setup() if @notifications.length > 0
setup: ->
console.log(@notifications)
$.ajax(
url: "/notifications.json"
dataType: "JSON"
method: "GET"
success: @handleSuccess
)
jQuery ->
new Notifications