1
我试图在GoRails教程之后建立一个通知系统。为了构建它,他们使用了我管理得很好的json文件。JSON turbolinks错误
一切工作正常,直到我有这条线在JSON文件为目标的html元素:
"<a class="dropdown-item" href='#{notification.url}'>#{notification.content.title}</a>"
巫婆产生我这个错误约turbolinks =>Error picture
所以,如果您有任何处理这个问题的建议,它会帮助我很多!
我的代码=
Notification.coffee(哪里是错误):
class Notifications
constructor: ->
@notifications = $("[data-behaviour='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.url}'>#{notification.content.title}</a>"
$("[data-behaviour='notification-items']").html(items)
jQuery ->
new Notifications
导航栏访问量:
<li class="dropdown" data-behaviour="notifications">
<a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown" id="dropdownMenu1" tata-toggle="dropdown" aria-haspopup="true" aria-expended="false"> <i class="fa fa-bell" aria-hidden="true" style="font-size: 25px;"></i></a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" data-behaviour="notification-items">
<li class="dropdown-item">
<a href="">Action1</a>
</li>
<li class="dropdown-item">
<a> Action2 </a>
</li>
</ul>
</li>
而且奖金,JSON文件:
json.array! @notifications do |notification|
json.id notification.id
json.receiver notification.receiver.pseudo
json.sender notification.sender.pseudo
json.title notification.title
json.content notification.content.title
json.url group_path(notification.content.group, anchor: "post_iter(#{notification.content.id})")
end
包含'layout.html.erb'中的实际代码,该代码导致问题中的语法错误和错误消息为文本。这里的其他一切都是无关紧要的。 – max
嗨@max,感谢您的回答,以及布局中的错误,它是引用js turbolinks的行,并且导致错误的行是我添加到咖啡文件中的行。 (“